Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 2 | * Video capture interface for Linux version 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 4 | * A generic video device interface for the LINUX operating system |
| 5 | * using a set of device structures/vectors for low level operations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 12 | * Authors: Alan Cox, <alan@redhat.com> (version 1) |
| 13 | * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
| 15 | * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com> |
| 16 | * - Added procfs support |
| 17 | */ |
| 18 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 19 | #define dbgarg(cmd, fmt, arg...) \ |
Enrico Scholz | 474ce78 | 2006-10-09 16:27:05 -0300 | [diff] [blame] | 20 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 21 | printk (KERN_DEBUG "%s: ", vfd->name); \ |
| 22 | v4l_printk_ioctl(cmd); \ |
Enrico Scholz | 474ce78 | 2006-10-09 16:27:05 -0300 | [diff] [blame] | 23 | printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); \ |
| 24 | } |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 25 | |
| 26 | #define dbgarg2(fmt, arg...) \ |
| 27 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \ |
| 28 | printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/types.h> |
| 32 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/smp_lock.h> |
| 34 | #include <linux/mm.h> |
| 35 | #include <linux/string.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/kmod.h> |
| 39 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/uaccess.h> |
| 41 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 43 | #define __OLD_VIDIOC_ /* To allow fixing old calls*/ |
| 44 | #include <linux/videodev2.h> |
| 45 | |
| 46 | #ifdef CONFIG_VIDEO_V4L1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <linux/videodev.h> |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 48 | #endif |
| 49 | #include <media/v4l2-common.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define VIDEO_NUM_DEVICES 256 |
| 52 | #define VIDEO_NAME "video4linux" |
| 53 | |
| 54 | /* |
| 55 | * sysfs stuff |
| 56 | */ |
| 57 | |
| 58 | static ssize_t show_name(struct class_device *cd, char *buf) |
| 59 | { |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 60 | struct video_device *vfd = container_of(cd, struct video_device, |
| 61 | class_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name); |
| 63 | } |
| 64 | |
| 65 | static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 66 | |
| 67 | struct video_device *video_device_alloc(void) |
| 68 | { |
| 69 | struct video_device *vfd; |
| 70 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 71 | vfd = kzalloc(sizeof(*vfd),GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return vfd; |
| 73 | } |
| 74 | |
| 75 | void video_device_release(struct video_device *vfd) |
| 76 | { |
| 77 | kfree(vfd); |
| 78 | } |
| 79 | |
| 80 | static void video_release(struct class_device *cd) |
| 81 | { |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 82 | struct video_device *vfd = container_of(cd, struct video_device, |
| 83 | class_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
Mauro Carvalho Chehab | d21838d | 2006-01-09 15:25:21 -0200 | [diff] [blame] | 85 | #if 1 |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 86 | /* needed until all drivers are fixed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | if (!vfd->release) |
| 88 | return; |
| 89 | #endif |
| 90 | vfd->release(vfd); |
| 91 | } |
| 92 | |
| 93 | static struct class video_class = { |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 94 | .name = VIDEO_NAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | .release = video_release, |
| 96 | }; |
| 97 | |
| 98 | /* |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 99 | * Active devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | */ |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | static struct video_device *video_device[VIDEO_NUM_DEVICES]; |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 103 | static DEFINE_MUTEX(videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | struct video_device* video_devdata(struct file *file) |
| 106 | { |
Josef Sipek | 723731b | 2006-12-08 02:37:47 -0800 | [diff] [blame] | 107 | return video_device[iminor(file->f_path.dentry->d_inode)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 111 | * Open a video device - FIXME: Obsoleted |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | */ |
| 113 | static int video_open(struct inode *inode, struct file *file) |
| 114 | { |
| 115 | unsigned int minor = iminor(inode); |
| 116 | int err = 0; |
| 117 | struct video_device *vfl; |
Arjan van de Ven | 99ac48f | 2006-03-28 01:56:41 -0800 | [diff] [blame] | 118 | const struct file_operations *old_fops; |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | if(minor>=VIDEO_NUM_DEVICES) |
| 121 | return -ENODEV; |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 122 | mutex_lock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | vfl=video_device[minor]; |
| 124 | if(vfl==NULL) { |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 125 | mutex_unlock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | request_module("char-major-%d-%d", VIDEO_MAJOR, minor); |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 127 | mutex_lock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | vfl=video_device[minor]; |
| 129 | if (vfl==NULL) { |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 130 | mutex_unlock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return -ENODEV; |
| 132 | } |
| 133 | } |
| 134 | old_fops = file->f_op; |
| 135 | file->f_op = fops_get(vfl->fops); |
| 136 | if(file->f_op->open) |
| 137 | err = file->f_op->open(inode,file); |
| 138 | if (err) { |
| 139 | fops_put(file->f_op); |
| 140 | file->f_op = fops_get(old_fops); |
| 141 | } |
| 142 | fops_put(old_fops); |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 143 | mutex_unlock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return err; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * helper function -- handles userspace copying for ioctl arguments |
| 149 | */ |
| 150 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 151 | #ifdef __OLD_VIDIOC_ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | static unsigned int |
| 153 | video_fix_command(unsigned int cmd) |
| 154 | { |
| 155 | switch (cmd) { |
| 156 | case VIDIOC_OVERLAY_OLD: |
| 157 | cmd = VIDIOC_OVERLAY; |
| 158 | break; |
| 159 | case VIDIOC_S_PARM_OLD: |
| 160 | cmd = VIDIOC_S_PARM; |
| 161 | break; |
| 162 | case VIDIOC_S_CTRL_OLD: |
| 163 | cmd = VIDIOC_S_CTRL; |
| 164 | break; |
| 165 | case VIDIOC_G_AUDIO_OLD: |
| 166 | cmd = VIDIOC_G_AUDIO; |
| 167 | break; |
| 168 | case VIDIOC_G_AUDOUT_OLD: |
| 169 | cmd = VIDIOC_G_AUDOUT; |
| 170 | break; |
| 171 | case VIDIOC_CROPCAP_OLD: |
| 172 | cmd = VIDIOC_CROPCAP; |
| 173 | break; |
| 174 | } |
| 175 | return cmd; |
| 176 | } |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 177 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 179 | /* |
| 180 | * Obsolete usercopy function - Should be removed soon |
| 181 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | int |
| 183 | video_usercopy(struct inode *inode, struct file *file, |
| 184 | unsigned int cmd, unsigned long arg, |
| 185 | int (*func)(struct inode *inode, struct file *file, |
| 186 | unsigned int cmd, void *arg)) |
| 187 | { |
| 188 | char sbuf[128]; |
| 189 | void *mbuf = NULL; |
| 190 | void *parg = NULL; |
| 191 | int err = -EINVAL; |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 192 | int is_ext_ctrl; |
| 193 | size_t ctrls_size = 0; |
| 194 | void __user *user_ptr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 196 | #ifdef __OLD_VIDIOC_ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | cmd = video_fix_command(cmd); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 198 | #endif |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 199 | is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS || |
| 200 | cmd == VIDIOC_TRY_EXT_CTRLS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | /* Copy arguments into temp kernel buffer */ |
| 203 | switch (_IOC_DIR(cmd)) { |
| 204 | case _IOC_NONE: |
| 205 | parg = NULL; |
| 206 | break; |
| 207 | case _IOC_READ: |
| 208 | case _IOC_WRITE: |
| 209 | case (_IOC_WRITE | _IOC_READ): |
| 210 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
| 211 | parg = sbuf; |
| 212 | } else { |
| 213 | /* too big to allocate from stack */ |
| 214 | mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL); |
| 215 | if (NULL == mbuf) |
| 216 | return -ENOMEM; |
| 217 | parg = mbuf; |
| 218 | } |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | err = -EFAULT; |
| 221 | if (_IOC_DIR(cmd) & _IOC_WRITE) |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 222 | if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | goto out; |
| 224 | break; |
| 225 | } |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 226 | if (is_ext_ctrl) { |
| 227 | struct v4l2_ext_controls *p = parg; |
| 228 | |
| 229 | /* In case of an error, tell the caller that it wasn't |
| 230 | a specific control that caused it. */ |
| 231 | p->error_idx = p->count; |
| 232 | user_ptr = (void __user *)p->controls; |
| 233 | if (p->count) { |
| 234 | ctrls_size = sizeof(struct v4l2_ext_control) * p->count; |
| 235 | /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */ |
| 236 | mbuf = kmalloc(ctrls_size, GFP_KERNEL); |
| 237 | err = -ENOMEM; |
| 238 | if (NULL == mbuf) |
| 239 | goto out_ext_ctrl; |
| 240 | err = -EFAULT; |
| 241 | if (copy_from_user(mbuf, user_ptr, ctrls_size)) |
| 242 | goto out_ext_ctrl; |
| 243 | p->controls = mbuf; |
| 244 | } |
| 245 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | /* call driver */ |
| 248 | err = func(inode, file, cmd, parg); |
| 249 | if (err == -ENOIOCTLCMD) |
| 250 | err = -EINVAL; |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 251 | if (is_ext_ctrl) { |
| 252 | struct v4l2_ext_controls *p = parg; |
| 253 | |
| 254 | p->controls = (void *)user_ptr; |
| 255 | if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size)) |
| 256 | err = -EFAULT; |
| 257 | goto out_ext_ctrl; |
| 258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | if (err < 0) |
| 260 | goto out; |
| 261 | |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 262 | out_ext_ctrl: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | /* Copy results into user buffer */ |
| 264 | switch (_IOC_DIR(cmd)) |
| 265 | { |
| 266 | case _IOC_READ: |
| 267 | case (_IOC_WRITE | _IOC_READ): |
| 268 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) |
| 269 | err = -EFAULT; |
| 270 | break; |
| 271 | } |
| 272 | |
| 273 | out: |
Jesper Juhl | 2ea7533 | 2005-11-07 01:01:31 -0800 | [diff] [blame] | 274 | kfree(mbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | return err; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * open/release helper functions -- handle exclusive opens |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 280 | * Should be removed soon |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | */ |
| 282 | int video_exclusive_open(struct inode *inode, struct file *file) |
| 283 | { |
| 284 | struct video_device *vfl = video_devdata(file); |
| 285 | int retval = 0; |
| 286 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 287 | mutex_lock(&vfl->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (vfl->users) { |
| 289 | retval = -EBUSY; |
| 290 | } else { |
| 291 | vfl->users++; |
| 292 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 293 | mutex_unlock(&vfl->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return retval; |
| 295 | } |
| 296 | |
| 297 | int video_exclusive_release(struct inode *inode, struct file *file) |
| 298 | { |
| 299 | struct video_device *vfl = video_devdata(file); |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | vfl->users--; |
| 302 | return 0; |
| 303 | } |
| 304 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 305 | static char *v4l2_memory_names[] = { |
| 306 | [V4L2_MEMORY_MMAP] = "mmap", |
| 307 | [V4L2_MEMORY_USERPTR] = "userptr", |
| 308 | [V4L2_MEMORY_OVERLAY] = "overlay", |
| 309 | }; |
| 310 | |
| 311 | |
| 312 | /* FIXME: Those stuff are replicated also on v4l2-common.c */ |
| 313 | static char *v4l2_type_names_FIXME[] = { |
| 314 | [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap", |
| 315 | [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over", |
| 316 | [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out", |
| 317 | [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", |
| 318 | [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", |
| 319 | [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out", |
| 320 | [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture", |
| 321 | [V4L2_BUF_TYPE_PRIVATE] = "private", |
| 322 | }; |
| 323 | |
| 324 | static char *v4l2_field_names_FIXME[] = { |
| 325 | [V4L2_FIELD_ANY] = "any", |
| 326 | [V4L2_FIELD_NONE] = "none", |
| 327 | [V4L2_FIELD_TOP] = "top", |
| 328 | [V4L2_FIELD_BOTTOM] = "bottom", |
| 329 | [V4L2_FIELD_INTERLACED] = "interlaced", |
| 330 | [V4L2_FIELD_SEQ_TB] = "seq-tb", |
| 331 | [V4L2_FIELD_SEQ_BT] = "seq-bt", |
| 332 | [V4L2_FIELD_ALTERNATE] = "alternate", |
| 333 | }; |
| 334 | |
| 335 | #define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown" |
| 336 | |
| 337 | static void dbgbuf(unsigned int cmd, struct video_device *vfd, |
| 338 | struct v4l2_buffer *p) |
| 339 | { |
| 340 | struct v4l2_timecode *tc=&p->timecode; |
| 341 | |
| 342 | dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, " |
| 343 | "bytesused=%d, flags=0x%08d, " |
Mauro Carvalho Chehab | bf5dbed | 2006-12-01 12:39:46 -0300 | [diff] [blame] | 344 | "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n", |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 345 | (p->timestamp.tv_sec/3600), |
| 346 | (int)(p->timestamp.tv_sec/60)%60, |
| 347 | (int)(p->timestamp.tv_sec%60), |
| 348 | p->timestamp.tv_usec, |
| 349 | p->index, |
| 350 | prt_names(p->type,v4l2_type_names_FIXME), |
| 351 | p->bytesused,p->flags, |
| 352 | p->field,p->sequence, |
| 353 | prt_names(p->memory,v4l2_memory_names), |
Mauro Carvalho Chehab | bf5dbed | 2006-12-01 12:39:46 -0300 | [diff] [blame] | 354 | p->m.userptr, p->length); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 355 | dbgarg2 ("timecode= %02d:%02d:%02d type=%d, " |
| 356 | "flags=0x%08d, frames=%d, userbits=0x%08x\n", |
| 357 | tc->hours,tc->minutes,tc->seconds, |
Mauro Carvalho Chehab | c18cb01 | 2006-06-23 07:05:22 -0300 | [diff] [blame] | 358 | tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | static inline void dbgrect(struct video_device *vfd, char *s, |
| 362 | struct v4l2_rect *r) |
| 363 | { |
| 364 | dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top, |
| 365 | r->width, r->height); |
| 366 | }; |
| 367 | |
| 368 | static inline void v4l_print_pix_fmt (struct video_device *vfd, |
| 369 | struct v4l2_pix_format *fmt) |
| 370 | { |
Mauro Carvalho Chehab | bf5dbed | 2006-12-01 12:39:46 -0300 | [diff] [blame] | 371 | dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, " |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 372 | "bytesperline=%d sizeimage=%d, colorspace=%d\n", |
Mauro Carvalho Chehab | bf5dbed | 2006-12-01 12:39:46 -0300 | [diff] [blame] | 373 | fmt->width,fmt->height, |
| 374 | (fmt->pixelformat & 0xff), |
| 375 | (fmt->pixelformat >> 8) & 0xff, |
| 376 | (fmt->pixelformat >> 16) & 0xff, |
| 377 | (fmt->pixelformat >> 24) & 0xff, |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 378 | prt_names(fmt->field,v4l2_field_names_FIXME), |
| 379 | fmt->bytesperline,fmt->sizeimage,fmt->colorspace); |
| 380 | }; |
| 381 | |
| 382 | |
| 383 | static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type) |
| 384 | { |
| 385 | switch (type) { |
| 386 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 387 | if (vfd->vidioc_try_fmt_cap) |
| 388 | return (0); |
| 389 | break; |
| 390 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 391 | if (vfd->vidioc_try_fmt_overlay) |
| 392 | return (0); |
| 393 | break; |
| 394 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 395 | if (vfd->vidioc_try_fmt_vbi) |
| 396 | return (0); |
| 397 | break; |
| 398 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 399 | if (vfd->vidioc_try_fmt_vbi_output) |
| 400 | return (0); |
| 401 | break; |
| 402 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 403 | if (vfd->vidioc_try_fmt_vbi_capture) |
| 404 | return (0); |
| 405 | break; |
| 406 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 407 | if (vfd->vidioc_try_fmt_video_output) |
| 408 | return (0); |
| 409 | break; |
| 410 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
| 411 | if (vfd->vidioc_try_fmt_vbi_output) |
| 412 | return (0); |
| 413 | break; |
| 414 | case V4L2_BUF_TYPE_PRIVATE: |
| 415 | if (vfd->vidioc_try_fmt_type_private) |
| 416 | return (0); |
| 417 | break; |
| 418 | } |
| 419 | return (-EINVAL); |
| 420 | } |
| 421 | |
| 422 | static int __video_do_ioctl(struct inode *inode, struct file *file, |
| 423 | unsigned int cmd, void *arg) |
| 424 | { |
| 425 | struct video_device *vfd = video_devdata(file); |
| 426 | void *fh = file->private_data; |
| 427 | int ret = -EINVAL; |
| 428 | |
| 429 | if ( (vfd->debug & V4L2_DEBUG_IOCTL) && |
| 430 | !(vfd->debug | V4L2_DEBUG_IOCTL_ARG)) { |
| 431 | v4l_print_ioctl(vfd->name, cmd); |
| 432 | } |
| 433 | |
Mauro Carvalho Chehab | 207705c | 2006-11-20 12:13:25 -0300 | [diff] [blame] | 434 | if (_IOC_TYPE(cmd)=='v') |
| 435 | return v4l_compat_translate_ioctl(inode,file,cmd,arg, |
| 436 | __video_do_ioctl); |
| 437 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 438 | switch(cmd) { |
| 439 | /* --- capabilities ------------------------------------------ */ |
| 440 | case VIDIOC_QUERYCAP: |
| 441 | { |
| 442 | struct v4l2_capability *cap = (struct v4l2_capability*)arg; |
| 443 | memset(cap, 0, sizeof(*cap)); |
| 444 | |
| 445 | if (!vfd->vidioc_querycap) |
| 446 | break; |
| 447 | |
| 448 | ret=vfd->vidioc_querycap(file, fh, cap); |
| 449 | if (!ret) |
| 450 | dbgarg (cmd, "driver=%s, card=%s, bus=%s, " |
| 451 | "version=0x%08x, " |
| 452 | "capabilities=0x%08x\n", |
| 453 | cap->driver,cap->card,cap->bus_info, |
| 454 | cap->version, |
| 455 | cap->capabilities); |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | /* --- priority ------------------------------------------ */ |
| 460 | case VIDIOC_G_PRIORITY: |
| 461 | { |
| 462 | enum v4l2_priority *p=arg; |
| 463 | |
| 464 | if (!vfd->vidioc_g_priority) |
| 465 | break; |
| 466 | ret=vfd->vidioc_g_priority(file, fh, p); |
| 467 | if (!ret) |
| 468 | dbgarg(cmd, "priority is %d\n", *p); |
| 469 | break; |
| 470 | } |
| 471 | case VIDIOC_S_PRIORITY: |
| 472 | { |
| 473 | enum v4l2_priority *p=arg; |
| 474 | |
| 475 | if (!vfd->vidioc_s_priority) |
| 476 | break; |
| 477 | dbgarg(cmd, "setting priority to %d\n", *p); |
| 478 | ret=vfd->vidioc_s_priority(file, fh, *p); |
| 479 | break; |
| 480 | } |
| 481 | |
| 482 | /* --- capture ioctls ---------------------------------------- */ |
| 483 | case VIDIOC_ENUM_FMT: |
| 484 | { |
| 485 | struct v4l2_fmtdesc *f = arg; |
| 486 | enum v4l2_buf_type type; |
| 487 | unsigned int index; |
| 488 | |
| 489 | index = f->index; |
| 490 | type = f->type; |
| 491 | memset(f,0,sizeof(*f)); |
| 492 | f->index = index; |
| 493 | f->type = type; |
| 494 | |
| 495 | switch (type) { |
| 496 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 497 | if (vfd->vidioc_enum_fmt_cap) |
| 498 | ret=vfd->vidioc_enum_fmt_cap(file, fh, f); |
| 499 | break; |
| 500 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 501 | if (vfd->vidioc_enum_fmt_overlay) |
| 502 | ret=vfd->vidioc_enum_fmt_overlay(file, fh, f); |
| 503 | break; |
| 504 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 505 | if (vfd->vidioc_enum_fmt_vbi) |
| 506 | ret=vfd->vidioc_enum_fmt_vbi(file, fh, f); |
| 507 | break; |
| 508 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 509 | if (vfd->vidioc_enum_fmt_vbi_output) |
| 510 | ret=vfd->vidioc_enum_fmt_vbi_output(file, |
| 511 | fh, f); |
| 512 | break; |
| 513 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 514 | if (vfd->vidioc_enum_fmt_vbi_capture) |
| 515 | ret=vfd->vidioc_enum_fmt_vbi_capture(file, |
| 516 | fh, f); |
| 517 | break; |
| 518 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 519 | if (vfd->vidioc_enum_fmt_video_output) |
| 520 | ret=vfd->vidioc_enum_fmt_video_output(file, |
| 521 | fh, f); |
| 522 | break; |
| 523 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
| 524 | if (vfd->vidioc_enum_fmt_vbi_output) |
| 525 | ret=vfd->vidioc_enum_fmt_vbi_output(file, |
| 526 | fh, f); |
| 527 | break; |
| 528 | case V4L2_BUF_TYPE_PRIVATE: |
| 529 | if (vfd->vidioc_enum_fmt_type_private) |
| 530 | ret=vfd->vidioc_enum_fmt_type_private(file, |
| 531 | fh, f); |
| 532 | break; |
| 533 | } |
| 534 | if (!ret) |
| 535 | dbgarg (cmd, "index=%d, type=%d, flags=%d, " |
Mauro Carvalho Chehab | bf5dbed | 2006-12-01 12:39:46 -0300 | [diff] [blame] | 536 | "pixelformat=%c%c%c%c, description='%s'\n", |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 537 | f->index, f->type, f->flags, |
Mauro Carvalho Chehab | bf5dbed | 2006-12-01 12:39:46 -0300 | [diff] [blame] | 538 | (f->pixelformat & 0xff), |
| 539 | (f->pixelformat >> 8) & 0xff, |
| 540 | (f->pixelformat >> 16) & 0xff, |
| 541 | (f->pixelformat >> 24) & 0xff, |
| 542 | f->description); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 543 | break; |
| 544 | } |
| 545 | case VIDIOC_G_FMT: |
| 546 | { |
| 547 | struct v4l2_format *f = (struct v4l2_format *)arg; |
| 548 | enum v4l2_buf_type type=f->type; |
| 549 | |
| 550 | memset(&f->fmt.pix,0,sizeof(f->fmt.pix)); |
| 551 | f->type=type; |
| 552 | |
| 553 | /* FIXME: Should be one dump per type */ |
| 554 | dbgarg (cmd, "type=%s\n", prt_names(type, |
| 555 | v4l2_type_names_FIXME)); |
| 556 | |
| 557 | switch (type) { |
| 558 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 559 | if (vfd->vidioc_g_fmt_cap) |
| 560 | ret=vfd->vidioc_g_fmt_cap(file, fh, f); |
| 561 | if (!ret) |
| 562 | v4l_print_pix_fmt(vfd,&f->fmt.pix); |
| 563 | break; |
| 564 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 565 | if (vfd->vidioc_g_fmt_overlay) |
| 566 | ret=vfd->vidioc_g_fmt_overlay(file, fh, f); |
| 567 | break; |
| 568 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 569 | if (vfd->vidioc_g_fmt_vbi) |
| 570 | ret=vfd->vidioc_g_fmt_vbi(file, fh, f); |
| 571 | break; |
| 572 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 573 | if (vfd->vidioc_g_fmt_vbi_output) |
| 574 | ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f); |
| 575 | break; |
| 576 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 577 | if (vfd->vidioc_g_fmt_vbi_capture) |
| 578 | ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f); |
| 579 | break; |
| 580 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 581 | if (vfd->vidioc_g_fmt_video_output) |
| 582 | ret=vfd->vidioc_g_fmt_video_output(file, |
| 583 | fh, f); |
| 584 | break; |
| 585 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
| 586 | if (vfd->vidioc_g_fmt_vbi_output) |
| 587 | ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f); |
| 588 | break; |
| 589 | case V4L2_BUF_TYPE_PRIVATE: |
| 590 | if (vfd->vidioc_g_fmt_type_private) |
| 591 | ret=vfd->vidioc_g_fmt_type_private(file, |
| 592 | fh, f); |
| 593 | break; |
| 594 | } |
| 595 | |
| 596 | break; |
| 597 | } |
| 598 | case VIDIOC_S_FMT: |
| 599 | { |
| 600 | struct v4l2_format *f = (struct v4l2_format *)arg; |
| 601 | |
| 602 | /* FIXME: Should be one dump per type */ |
| 603 | dbgarg (cmd, "type=%s\n", prt_names(f->type, |
| 604 | v4l2_type_names_FIXME)); |
| 605 | |
| 606 | switch (f->type) { |
| 607 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 608 | v4l_print_pix_fmt(vfd,&f->fmt.pix); |
| 609 | if (vfd->vidioc_s_fmt_cap) |
| 610 | ret=vfd->vidioc_s_fmt_cap(file, fh, f); |
| 611 | break; |
| 612 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 613 | if (vfd->vidioc_s_fmt_overlay) |
| 614 | ret=vfd->vidioc_s_fmt_overlay(file, fh, f); |
| 615 | break; |
| 616 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 617 | if (vfd->vidioc_s_fmt_vbi) |
| 618 | ret=vfd->vidioc_s_fmt_vbi(file, fh, f); |
| 619 | break; |
| 620 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 621 | if (vfd->vidioc_s_fmt_vbi_output) |
| 622 | ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f); |
| 623 | break; |
| 624 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 625 | if (vfd->vidioc_s_fmt_vbi_capture) |
| 626 | ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f); |
| 627 | break; |
| 628 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 629 | if (vfd->vidioc_s_fmt_video_output) |
| 630 | ret=vfd->vidioc_s_fmt_video_output(file, |
| 631 | fh, f); |
| 632 | break; |
| 633 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
| 634 | if (vfd->vidioc_s_fmt_vbi_output) |
| 635 | ret=vfd->vidioc_s_fmt_vbi_output(file, |
| 636 | fh, f); |
| 637 | break; |
| 638 | case V4L2_BUF_TYPE_PRIVATE: |
| 639 | if (vfd->vidioc_s_fmt_type_private) |
| 640 | ret=vfd->vidioc_s_fmt_type_private(file, |
| 641 | fh, f); |
| 642 | break; |
| 643 | } |
| 644 | break; |
| 645 | } |
| 646 | case VIDIOC_TRY_FMT: |
| 647 | { |
| 648 | struct v4l2_format *f = (struct v4l2_format *)arg; |
| 649 | |
| 650 | /* FIXME: Should be one dump per type */ |
| 651 | dbgarg (cmd, "type=%s\n", prt_names(f->type, |
| 652 | v4l2_type_names_FIXME)); |
| 653 | switch (f->type) { |
| 654 | case V4L2_BUF_TYPE_VIDEO_CAPTURE: |
| 655 | if (vfd->vidioc_try_fmt_cap) |
| 656 | ret=vfd->vidioc_try_fmt_cap(file, fh, f); |
| 657 | if (!ret) |
| 658 | v4l_print_pix_fmt(vfd,&f->fmt.pix); |
| 659 | break; |
| 660 | case V4L2_BUF_TYPE_VIDEO_OVERLAY: |
| 661 | if (vfd->vidioc_try_fmt_overlay) |
| 662 | ret=vfd->vidioc_try_fmt_overlay(file, fh, f); |
| 663 | break; |
| 664 | case V4L2_BUF_TYPE_VBI_CAPTURE: |
| 665 | if (vfd->vidioc_try_fmt_vbi) |
| 666 | ret=vfd->vidioc_try_fmt_vbi(file, fh, f); |
| 667 | break; |
| 668 | case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT: |
| 669 | if (vfd->vidioc_try_fmt_vbi_output) |
| 670 | ret=vfd->vidioc_try_fmt_vbi_output(file, |
| 671 | fh, f); |
| 672 | break; |
| 673 | case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE: |
| 674 | if (vfd->vidioc_try_fmt_vbi_capture) |
| 675 | ret=vfd->vidioc_try_fmt_vbi_capture(file, |
| 676 | fh, f); |
| 677 | break; |
| 678 | case V4L2_BUF_TYPE_VIDEO_OUTPUT: |
| 679 | if (vfd->vidioc_try_fmt_video_output) |
| 680 | ret=vfd->vidioc_try_fmt_video_output(file, |
| 681 | fh, f); |
| 682 | break; |
| 683 | case V4L2_BUF_TYPE_VBI_OUTPUT: |
| 684 | if (vfd->vidioc_try_fmt_vbi_output) |
| 685 | ret=vfd->vidioc_try_fmt_vbi_output(file, |
| 686 | fh, f); |
| 687 | break; |
| 688 | case V4L2_BUF_TYPE_PRIVATE: |
| 689 | if (vfd->vidioc_try_fmt_type_private) |
| 690 | ret=vfd->vidioc_try_fmt_type_private(file, |
| 691 | fh, f); |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | break; |
| 696 | } |
| 697 | /* FIXME: Those buf reqs could be handled here, |
| 698 | with some changes on videobuf to allow its header to be included at |
| 699 | videodev2.h or being merged at videodev2. |
| 700 | */ |
| 701 | case VIDIOC_REQBUFS: |
| 702 | { |
| 703 | struct v4l2_requestbuffers *p=arg; |
| 704 | |
| 705 | if (!vfd->vidioc_reqbufs) |
| 706 | break; |
| 707 | ret = check_fmt (vfd, p->type); |
| 708 | if (ret) |
| 709 | break; |
| 710 | |
| 711 | ret=vfd->vidioc_reqbufs(file, fh, p); |
| 712 | dbgarg (cmd, "count=%d, type=%s, memory=%s\n", |
| 713 | p->count, |
| 714 | prt_names(p->type,v4l2_type_names_FIXME), |
| 715 | prt_names(p->memory,v4l2_memory_names)); |
| 716 | break; |
| 717 | } |
| 718 | case VIDIOC_QUERYBUF: |
| 719 | { |
| 720 | struct v4l2_buffer *p=arg; |
| 721 | |
| 722 | if (!vfd->vidioc_querybuf) |
| 723 | break; |
| 724 | ret = check_fmt (vfd, p->type); |
| 725 | if (ret) |
| 726 | break; |
| 727 | |
| 728 | ret=vfd->vidioc_querybuf(file, fh, p); |
| 729 | if (!ret) |
| 730 | dbgbuf(cmd,vfd,p); |
| 731 | break; |
| 732 | } |
| 733 | case VIDIOC_QBUF: |
| 734 | { |
| 735 | struct v4l2_buffer *p=arg; |
| 736 | |
| 737 | if (!vfd->vidioc_qbuf) |
| 738 | break; |
| 739 | ret = check_fmt (vfd, p->type); |
| 740 | if (ret) |
| 741 | break; |
| 742 | |
| 743 | ret=vfd->vidioc_qbuf(file, fh, p); |
| 744 | if (!ret) |
| 745 | dbgbuf(cmd,vfd,p); |
| 746 | break; |
| 747 | } |
| 748 | case VIDIOC_DQBUF: |
| 749 | { |
| 750 | struct v4l2_buffer *p=arg; |
Sascha Hauer | c93a5c3 | 2006-09-11 09:49:19 -0300 | [diff] [blame] | 751 | if (!vfd->vidioc_dqbuf) |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 752 | break; |
| 753 | ret = check_fmt (vfd, p->type); |
| 754 | if (ret) |
| 755 | break; |
| 756 | |
Sascha Hauer | c93a5c3 | 2006-09-11 09:49:19 -0300 | [diff] [blame] | 757 | ret=vfd->vidioc_dqbuf(file, fh, p); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 758 | if (!ret) |
| 759 | dbgbuf(cmd,vfd,p); |
| 760 | break; |
| 761 | } |
| 762 | case VIDIOC_OVERLAY: |
| 763 | { |
| 764 | int *i = arg; |
| 765 | |
| 766 | if (!vfd->vidioc_overlay) |
| 767 | break; |
| 768 | dbgarg (cmd, "value=%d\n",*i); |
| 769 | ret=vfd->vidioc_overlay(file, fh, *i); |
| 770 | break; |
| 771 | } |
Mauro Carvalho Chehab | 0dfa9ab | 2006-08-08 09:10:10 -0300 | [diff] [blame] | 772 | #ifdef CONFIG_VIDEO_V4L1_COMPAT |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 773 | /* --- streaming capture ------------------------------------- */ |
| 774 | case VIDIOCGMBUF: |
| 775 | { |
| 776 | struct video_mbuf *p=arg; |
| 777 | |
Mauro Carvalho Chehab | 4ceb04e | 2006-06-17 08:52:30 -0300 | [diff] [blame] | 778 | memset(p,0,sizeof(p)); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 779 | |
| 780 | if (!vfd->vidiocgmbuf) |
| 781 | break; |
| 782 | ret=vfd->vidiocgmbuf(file, fh, p); |
| 783 | if (!ret) |
| 784 | dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n", |
| 785 | p->size, p->frames, |
| 786 | (unsigned long)p->offsets); |
| 787 | break; |
| 788 | } |
| 789 | #endif |
| 790 | case VIDIOC_G_FBUF: |
| 791 | { |
| 792 | struct v4l2_framebuffer *p=arg; |
| 793 | if (!vfd->vidioc_g_fbuf) |
| 794 | break; |
| 795 | ret=vfd->vidioc_g_fbuf(file, fh, arg); |
| 796 | if (!ret) { |
| 797 | dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n", |
| 798 | p->capability,p->flags, |
| 799 | (unsigned long)p->base); |
| 800 | v4l_print_pix_fmt (vfd, &p->fmt); |
| 801 | } |
| 802 | break; |
| 803 | } |
| 804 | case VIDIOC_S_FBUF: |
| 805 | { |
| 806 | struct v4l2_framebuffer *p=arg; |
| 807 | if (!vfd->vidioc_s_fbuf) |
| 808 | break; |
| 809 | |
| 810 | dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n", |
| 811 | p->capability,p->flags,(unsigned long)p->base); |
| 812 | v4l_print_pix_fmt (vfd, &p->fmt); |
| 813 | ret=vfd->vidioc_s_fbuf(file, fh, arg); |
| 814 | |
| 815 | break; |
| 816 | } |
| 817 | case VIDIOC_STREAMON: |
| 818 | { |
| 819 | enum v4l2_buf_type i = *(int *)arg; |
| 820 | if (!vfd->vidioc_streamon) |
| 821 | break; |
| 822 | dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME)); |
| 823 | ret=vfd->vidioc_streamon(file, fh,i); |
| 824 | break; |
| 825 | } |
| 826 | case VIDIOC_STREAMOFF: |
| 827 | { |
| 828 | enum v4l2_buf_type i = *(int *)arg; |
| 829 | |
| 830 | if (!vfd->vidioc_streamoff) |
| 831 | break; |
| 832 | dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME)); |
| 833 | ret=vfd->vidioc_streamoff(file, fh, i); |
| 834 | break; |
| 835 | } |
| 836 | /* ---------- tv norms ---------- */ |
| 837 | case VIDIOC_ENUMSTD: |
| 838 | { |
| 839 | struct v4l2_standard *p = arg; |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 840 | v4l2_std_id id = vfd->tvnorms,curr_id=0; |
| 841 | unsigned int index = p->index,i; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 842 | |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 843 | if (index<0) { |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 844 | ret=-EINVAL; |
| 845 | break; |
| 846 | } |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 847 | |
| 848 | /* Return norm array on a canonical way */ |
| 849 | for (i=0;i<= index && id; i++) { |
| 850 | if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) { |
| 851 | curr_id = V4L2_STD_PAL; |
| 852 | } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) { |
| 853 | curr_id = V4L2_STD_PAL_BG; |
| 854 | } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) { |
| 855 | curr_id = V4L2_STD_PAL_DK; |
| 856 | } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) { |
| 857 | curr_id = V4L2_STD_PAL_B; |
| 858 | } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) { |
| 859 | curr_id = V4L2_STD_PAL_B1; |
| 860 | } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) { |
| 861 | curr_id = V4L2_STD_PAL_G; |
| 862 | } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) { |
| 863 | curr_id = V4L2_STD_PAL_H; |
| 864 | } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) { |
| 865 | curr_id = V4L2_STD_PAL_I; |
| 866 | } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) { |
| 867 | curr_id = V4L2_STD_PAL_D; |
| 868 | } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) { |
| 869 | curr_id = V4L2_STD_PAL_D1; |
| 870 | } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) { |
| 871 | curr_id = V4L2_STD_PAL_K; |
| 872 | } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) { |
| 873 | curr_id = V4L2_STD_PAL_M; |
| 874 | } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) { |
| 875 | curr_id = V4L2_STD_PAL_N; |
| 876 | } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) { |
| 877 | curr_id = V4L2_STD_PAL_Nc; |
| 878 | } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) { |
| 879 | curr_id = V4L2_STD_PAL_60; |
| 880 | } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) { |
| 881 | curr_id = V4L2_STD_NTSC; |
| 882 | } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) { |
| 883 | curr_id = V4L2_STD_NTSC_M; |
| 884 | } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) { |
| 885 | curr_id = V4L2_STD_NTSC_M_JP; |
| 886 | } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) { |
| 887 | curr_id = V4L2_STD_NTSC_443; |
| 888 | } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) { |
| 889 | curr_id = V4L2_STD_NTSC_M_KR; |
| 890 | } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) { |
| 891 | curr_id = V4L2_STD_SECAM; |
| 892 | } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) { |
| 893 | curr_id = V4L2_STD_SECAM_DK; |
| 894 | } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) { |
| 895 | curr_id = V4L2_STD_SECAM_B; |
| 896 | } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) { |
| 897 | curr_id = V4L2_STD_SECAM_D; |
| 898 | } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) { |
| 899 | curr_id = V4L2_STD_SECAM_G; |
| 900 | } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) { |
| 901 | curr_id = V4L2_STD_SECAM_H; |
| 902 | } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) { |
| 903 | curr_id = V4L2_STD_SECAM_K; |
| 904 | } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) { |
| 905 | curr_id = V4L2_STD_SECAM_K1; |
| 906 | } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) { |
| 907 | curr_id = V4L2_STD_SECAM_L; |
| 908 | } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) { |
| 909 | curr_id = V4L2_STD_SECAM_LC; |
| 910 | } else { |
| 911 | break; |
| 912 | } |
| 913 | id &= ~curr_id; |
| 914 | } |
| 915 | if (i<=index) |
| 916 | return -EINVAL; |
| 917 | |
| 918 | v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id)); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 919 | p->index = index; |
| 920 | |
| 921 | dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, " |
| 922 | "framelines=%d\n", p->index, |
| 923 | (unsigned long long)p->id, p->name, |
| 924 | p->frameperiod.numerator, |
| 925 | p->frameperiod.denominator, |
| 926 | p->framelines); |
| 927 | |
| 928 | ret=0; |
| 929 | break; |
| 930 | } |
| 931 | case VIDIOC_G_STD: |
| 932 | { |
| 933 | v4l2_std_id *id = arg; |
| 934 | |
| 935 | *id = vfd->current_norm; |
| 936 | |
| 937 | dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id); |
| 938 | |
| 939 | ret=0; |
| 940 | break; |
| 941 | } |
| 942 | case VIDIOC_S_STD: |
| 943 | { |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 944 | v4l2_std_id *id = arg,norm; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 945 | |
| 946 | dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id); |
| 947 | |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 948 | norm = (*id) & vfd->tvnorms; |
| 949 | if ( vfd->tvnorms && !norm) /* Check if std is supported */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 950 | break; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 951 | |
| 952 | /* Calls the specific handler */ |
| 953 | if (vfd->vidioc_s_std) |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 954 | ret=vfd->vidioc_s_std(file, fh, &norm); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 955 | else |
| 956 | ret=-EINVAL; |
| 957 | |
| 958 | /* Updates standard information */ |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 959 | if (ret>=0) |
| 960 | vfd->current_norm=norm; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 961 | |
| 962 | break; |
| 963 | } |
| 964 | case VIDIOC_QUERYSTD: |
| 965 | { |
| 966 | v4l2_std_id *p=arg; |
| 967 | |
| 968 | if (!vfd->vidioc_querystd) |
| 969 | break; |
| 970 | ret=vfd->vidioc_querystd(file, fh, arg); |
| 971 | if (!ret) |
| 972 | dbgarg (cmd, "detected std=%Lu\n", |
| 973 | (unsigned long long)*p); |
| 974 | break; |
| 975 | } |
| 976 | /* ------ input switching ---------- */ |
| 977 | /* FIXME: Inputs can be handled inside videodev2 */ |
| 978 | case VIDIOC_ENUMINPUT: |
| 979 | { |
| 980 | struct v4l2_input *p=arg; |
| 981 | int i=p->index; |
| 982 | |
| 983 | if (!vfd->vidioc_enum_input) |
| 984 | break; |
| 985 | memset(p, 0, sizeof(*p)); |
| 986 | p->index=i; |
| 987 | |
| 988 | ret=vfd->vidioc_enum_input(file, fh, p); |
| 989 | if (!ret) |
| 990 | dbgarg (cmd, "index=%d, name=%s, type=%d, " |
| 991 | "audioset=%d, " |
| 992 | "tuner=%d, std=%Ld, status=%d\n", |
| 993 | p->index,p->name,p->type,p->audioset, |
| 994 | p->tuner, |
| 995 | (unsigned long long)p->std, |
| 996 | p->status); |
| 997 | break; |
| 998 | } |
| 999 | case VIDIOC_G_INPUT: |
| 1000 | { |
| 1001 | unsigned int *i = arg; |
| 1002 | |
| 1003 | if (!vfd->vidioc_g_input) |
| 1004 | break; |
| 1005 | ret=vfd->vidioc_g_input(file, fh, i); |
| 1006 | if (!ret) |
| 1007 | dbgarg (cmd, "value=%d\n",*i); |
| 1008 | break; |
| 1009 | } |
| 1010 | case VIDIOC_S_INPUT: |
| 1011 | { |
| 1012 | unsigned int *i = arg; |
| 1013 | |
| 1014 | if (!vfd->vidioc_s_input) |
| 1015 | break; |
| 1016 | dbgarg (cmd, "value=%d\n",*i); |
| 1017 | ret=vfd->vidioc_s_input(file, fh, *i); |
| 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | /* ------ output switching ---------- */ |
| 1022 | case VIDIOC_G_OUTPUT: |
| 1023 | { |
| 1024 | unsigned int *i = arg; |
| 1025 | |
| 1026 | if (!vfd->vidioc_g_output) |
| 1027 | break; |
| 1028 | ret=vfd->vidioc_g_output(file, fh, i); |
| 1029 | if (!ret) |
| 1030 | dbgarg (cmd, "value=%d\n",*i); |
| 1031 | break; |
| 1032 | } |
| 1033 | case VIDIOC_S_OUTPUT: |
| 1034 | { |
| 1035 | unsigned int *i = arg; |
| 1036 | |
| 1037 | if (!vfd->vidioc_s_output) |
| 1038 | break; |
| 1039 | dbgarg (cmd, "value=%d\n",*i); |
| 1040 | ret=vfd->vidioc_s_output(file, fh, *i); |
| 1041 | break; |
| 1042 | } |
| 1043 | |
| 1044 | /* --- controls ---------------------------------------------- */ |
| 1045 | case VIDIOC_QUERYCTRL: |
| 1046 | { |
| 1047 | struct v4l2_queryctrl *p=arg; |
| 1048 | |
| 1049 | if (!vfd->vidioc_queryctrl) |
| 1050 | break; |
| 1051 | ret=vfd->vidioc_queryctrl(file, fh, p); |
| 1052 | |
| 1053 | if (!ret) |
| 1054 | dbgarg (cmd, "id=%d, type=%d, name=%s, " |
| 1055 | "min/max=%d/%d," |
| 1056 | " step=%d, default=%d, flags=0x%08x\n", |
| 1057 | p->id,p->type,p->name,p->minimum, |
| 1058 | p->maximum,p->step,p->default_value, |
| 1059 | p->flags); |
| 1060 | break; |
| 1061 | } |
| 1062 | case VIDIOC_G_CTRL: |
| 1063 | { |
| 1064 | struct v4l2_control *p = arg; |
| 1065 | |
| 1066 | if (!vfd->vidioc_g_ctrl) |
| 1067 | break; |
| 1068 | dbgarg(cmd, "Enum for index=%d\n", p->id); |
| 1069 | |
| 1070 | ret=vfd->vidioc_g_ctrl(file, fh, p); |
| 1071 | if (!ret) |
| 1072 | dbgarg2 ( "id=%d, value=%d\n", p->id, p->value); |
| 1073 | break; |
| 1074 | } |
| 1075 | case VIDIOC_S_CTRL: |
| 1076 | { |
| 1077 | struct v4l2_control *p = arg; |
| 1078 | |
| 1079 | if (!vfd->vidioc_s_ctrl) |
| 1080 | break; |
| 1081 | dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value); |
| 1082 | |
| 1083 | ret=vfd->vidioc_s_ctrl(file, fh, p); |
| 1084 | break; |
| 1085 | } |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 1086 | case VIDIOC_G_EXT_CTRLS: |
| 1087 | { |
| 1088 | struct v4l2_ext_controls *p = arg; |
| 1089 | |
| 1090 | if (vfd->vidioc_g_ext_ctrls) { |
| 1091 | dbgarg(cmd, "count=%d\n", p->count); |
| 1092 | |
| 1093 | ret=vfd->vidioc_g_ext_ctrls(file, fh, p); |
| 1094 | } |
| 1095 | break; |
| 1096 | } |
| 1097 | case VIDIOC_S_EXT_CTRLS: |
| 1098 | { |
| 1099 | struct v4l2_ext_controls *p = arg; |
| 1100 | |
| 1101 | if (vfd->vidioc_s_ext_ctrls) { |
| 1102 | dbgarg(cmd, "count=%d\n", p->count); |
| 1103 | |
| 1104 | ret=vfd->vidioc_s_ext_ctrls(file, fh, p); |
| 1105 | } |
| 1106 | break; |
| 1107 | } |
| 1108 | case VIDIOC_TRY_EXT_CTRLS: |
| 1109 | { |
| 1110 | struct v4l2_ext_controls *p = arg; |
| 1111 | |
| 1112 | if (vfd->vidioc_try_ext_ctrls) { |
| 1113 | dbgarg(cmd, "count=%d\n", p->count); |
| 1114 | |
| 1115 | ret=vfd->vidioc_try_ext_ctrls(file, fh, p); |
| 1116 | } |
| 1117 | break; |
| 1118 | } |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1119 | case VIDIOC_QUERYMENU: |
| 1120 | { |
| 1121 | struct v4l2_querymenu *p=arg; |
| 1122 | if (!vfd->vidioc_querymenu) |
| 1123 | break; |
| 1124 | ret=vfd->vidioc_querymenu(file, fh, p); |
| 1125 | if (!ret) |
| 1126 | dbgarg (cmd, "id=%d, index=%d, name=%s\n", |
| 1127 | p->id,p->index,p->name); |
| 1128 | break; |
| 1129 | } |
| 1130 | /* --- audio ---------------------------------------------- */ |
| 1131 | case VIDIOC_ENUMAUDIO: |
| 1132 | { |
| 1133 | struct v4l2_audio *p=arg; |
| 1134 | |
| 1135 | if (!vfd->vidioc_enumaudio) |
| 1136 | break; |
| 1137 | dbgarg(cmd, "Enum for index=%d\n", p->index); |
| 1138 | ret=vfd->vidioc_enumaudio(file, fh, p); |
| 1139 | if (!ret) |
| 1140 | dbgarg2("index=%d, name=%s, capability=%d, " |
| 1141 | "mode=%d\n",p->index,p->name, |
| 1142 | p->capability, p->mode); |
| 1143 | break; |
| 1144 | } |
| 1145 | case VIDIOC_G_AUDIO: |
| 1146 | { |
| 1147 | struct v4l2_audio *p=arg; |
Mauro Carvalho Chehab | 7964b1b | 2006-11-20 12:10:43 -0300 | [diff] [blame] | 1148 | __u32 index=p->index; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1149 | |
| 1150 | if (!vfd->vidioc_g_audio) |
| 1151 | break; |
Mauro Carvalho Chehab | 7964b1b | 2006-11-20 12:10:43 -0300 | [diff] [blame] | 1152 | |
| 1153 | memset(p,0,sizeof(*p)); |
| 1154 | p->index=index; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1155 | dbgarg(cmd, "Get for index=%d\n", p->index); |
| 1156 | ret=vfd->vidioc_g_audio(file, fh, p); |
| 1157 | if (!ret) |
| 1158 | dbgarg2("index=%d, name=%s, capability=%d, " |
| 1159 | "mode=%d\n",p->index, |
| 1160 | p->name,p->capability, p->mode); |
| 1161 | break; |
| 1162 | } |
| 1163 | case VIDIOC_S_AUDIO: |
| 1164 | { |
| 1165 | struct v4l2_audio *p=arg; |
| 1166 | |
| 1167 | if (!vfd->vidioc_s_audio) |
| 1168 | break; |
| 1169 | dbgarg(cmd, "index=%d, name=%s, capability=%d, " |
| 1170 | "mode=%d\n", p->index, p->name, |
| 1171 | p->capability, p->mode); |
| 1172 | ret=vfd->vidioc_s_audio(file, fh, p); |
| 1173 | break; |
| 1174 | } |
| 1175 | case VIDIOC_ENUMAUDOUT: |
| 1176 | { |
| 1177 | struct v4l2_audioout *p=arg; |
| 1178 | |
| 1179 | if (!vfd->vidioc_enumaudout) |
| 1180 | break; |
| 1181 | dbgarg(cmd, "Enum for index=%d\n", p->index); |
| 1182 | ret=vfd->vidioc_enumaudout(file, fh, p); |
| 1183 | if (!ret) |
| 1184 | dbgarg2("index=%d, name=%s, capability=%d, " |
| 1185 | "mode=%d\n", p->index, p->name, |
| 1186 | p->capability,p->mode); |
| 1187 | break; |
| 1188 | } |
| 1189 | case VIDIOC_G_AUDOUT: |
| 1190 | { |
| 1191 | struct v4l2_audioout *p=arg; |
| 1192 | |
| 1193 | if (!vfd->vidioc_g_audout) |
| 1194 | break; |
| 1195 | dbgarg(cmd, "Enum for index=%d\n", p->index); |
| 1196 | ret=vfd->vidioc_g_audout(file, fh, p); |
| 1197 | if (!ret) |
| 1198 | dbgarg2("index=%d, name=%s, capability=%d, " |
| 1199 | "mode=%d\n", p->index, p->name, |
| 1200 | p->capability,p->mode); |
| 1201 | break; |
| 1202 | } |
| 1203 | case VIDIOC_S_AUDOUT: |
| 1204 | { |
| 1205 | struct v4l2_audioout *p=arg; |
| 1206 | |
| 1207 | if (!vfd->vidioc_s_audout) |
| 1208 | break; |
| 1209 | dbgarg(cmd, "index=%d, name=%s, capability=%d, " |
| 1210 | "mode=%d\n", p->index, p->name, |
| 1211 | p->capability,p->mode); |
| 1212 | |
| 1213 | ret=vfd->vidioc_s_audout(file, fh, p); |
| 1214 | break; |
| 1215 | } |
| 1216 | case VIDIOC_G_MODULATOR: |
| 1217 | { |
| 1218 | struct v4l2_modulator *p=arg; |
| 1219 | if (!vfd->vidioc_g_modulator) |
| 1220 | break; |
| 1221 | ret=vfd->vidioc_g_modulator(file, fh, p); |
| 1222 | if (!ret) |
| 1223 | dbgarg(cmd, "index=%d, name=%s, " |
| 1224 | "capability=%d, rangelow=%d," |
| 1225 | " rangehigh=%d, txsubchans=%d\n", |
| 1226 | p->index, p->name,p->capability, |
| 1227 | p->rangelow, p->rangehigh, |
| 1228 | p->txsubchans); |
| 1229 | break; |
| 1230 | } |
| 1231 | case VIDIOC_S_MODULATOR: |
| 1232 | { |
| 1233 | struct v4l2_modulator *p=arg; |
| 1234 | if (!vfd->vidioc_s_modulator) |
| 1235 | break; |
| 1236 | dbgarg(cmd, "index=%d, name=%s, capability=%d, " |
| 1237 | "rangelow=%d, rangehigh=%d, txsubchans=%d\n", |
| 1238 | p->index, p->name,p->capability,p->rangelow, |
| 1239 | p->rangehigh,p->txsubchans); |
| 1240 | ret=vfd->vidioc_s_modulator(file, fh, p); |
| 1241 | break; |
| 1242 | } |
| 1243 | case VIDIOC_G_CROP: |
| 1244 | { |
| 1245 | struct v4l2_crop *p=arg; |
| 1246 | if (!vfd->vidioc_g_crop) |
| 1247 | break; |
| 1248 | ret=vfd->vidioc_g_crop(file, fh, p); |
| 1249 | if (!ret) { |
| 1250 | dbgarg(cmd, "type=%d\n", p->type); |
| 1251 | dbgrect(vfd, "", &p->c); |
| 1252 | } |
| 1253 | break; |
| 1254 | } |
| 1255 | case VIDIOC_S_CROP: |
| 1256 | { |
| 1257 | struct v4l2_crop *p=arg; |
| 1258 | if (!vfd->vidioc_s_crop) |
| 1259 | break; |
| 1260 | dbgarg(cmd, "type=%d\n", p->type); |
| 1261 | dbgrect(vfd, "", &p->c); |
| 1262 | ret=vfd->vidioc_s_crop(file, fh, p); |
| 1263 | break; |
| 1264 | } |
| 1265 | case VIDIOC_CROPCAP: |
| 1266 | { |
| 1267 | struct v4l2_cropcap *p=arg; |
| 1268 | /*FIXME: Should also show v4l2_fract pixelaspect */ |
| 1269 | if (!vfd->vidioc_cropcap) |
| 1270 | break; |
| 1271 | dbgarg(cmd, "type=%d\n", p->type); |
| 1272 | dbgrect(vfd, "bounds ", &p->bounds); |
| 1273 | dbgrect(vfd, "defrect ", &p->defrect); |
| 1274 | ret=vfd->vidioc_cropcap(file, fh, p); |
| 1275 | break; |
| 1276 | } |
| 1277 | case VIDIOC_G_MPEGCOMP: |
| 1278 | { |
| 1279 | struct v4l2_mpeg_compression *p=arg; |
Hans Verkuil | f81cf75 | 2006-06-18 16:54:20 -0300 | [diff] [blame] | 1280 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1281 | /*FIXME: Several fields not shown */ |
| 1282 | if (!vfd->vidioc_g_mpegcomp) |
| 1283 | break; |
| 1284 | ret=vfd->vidioc_g_mpegcomp(file, fh, p); |
| 1285 | if (!ret) |
| 1286 | dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d," |
| 1287 | " ts_pid_video=%d, ts_pid_pcr=%d, " |
| 1288 | "ps_size=%d, au_sample_rate=%d, " |
| 1289 | "au_pesid=%c, vi_frame_rate=%d, " |
| 1290 | "vi_frames_per_gop=%d, " |
| 1291 | "vi_bframes_count=%d, vi_pesid=%c\n", |
| 1292 | p->ts_pid_pmt,p->ts_pid_audio, |
| 1293 | p->ts_pid_video,p->ts_pid_pcr, |
| 1294 | p->ps_size, p->au_sample_rate, |
| 1295 | p->au_pesid, p->vi_frame_rate, |
| 1296 | p->vi_frames_per_gop, |
| 1297 | p->vi_bframes_count, p->vi_pesid); |
| 1298 | break; |
| 1299 | } |
| 1300 | case VIDIOC_S_MPEGCOMP: |
| 1301 | { |
| 1302 | struct v4l2_mpeg_compression *p=arg; |
| 1303 | /*FIXME: Several fields not shown */ |
| 1304 | if (!vfd->vidioc_s_mpegcomp) |
| 1305 | break; |
| 1306 | dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d, " |
| 1307 | "ts_pid_video=%d, ts_pid_pcr=%d, ps_size=%d, " |
| 1308 | "au_sample_rate=%d, au_pesid=%c, " |
| 1309 | "vi_frame_rate=%d, vi_frames_per_gop=%d, " |
| 1310 | "vi_bframes_count=%d, vi_pesid=%c\n", |
| 1311 | p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video, |
| 1312 | p->ts_pid_pcr, p->ps_size, p->au_sample_rate, |
| 1313 | p->au_pesid, p->vi_frame_rate, |
| 1314 | p->vi_frames_per_gop, p->vi_bframes_count, |
| 1315 | p->vi_pesid); |
| 1316 | ret=vfd->vidioc_s_mpegcomp(file, fh, p); |
| 1317 | break; |
| 1318 | } |
| 1319 | case VIDIOC_G_JPEGCOMP: |
| 1320 | { |
| 1321 | struct v4l2_jpegcompression *p=arg; |
| 1322 | if (!vfd->vidioc_g_jpegcomp) |
| 1323 | break; |
| 1324 | ret=vfd->vidioc_g_jpegcomp(file, fh, p); |
| 1325 | if (!ret) |
| 1326 | dbgarg (cmd, "quality=%d, APPn=%d, " |
| 1327 | "APP_len=%d, COM_len=%d, " |
| 1328 | "jpeg_markers=%d\n", |
| 1329 | p->quality,p->APPn,p->APP_len, |
| 1330 | p->COM_len,p->jpeg_markers); |
| 1331 | break; |
| 1332 | } |
| 1333 | case VIDIOC_S_JPEGCOMP: |
| 1334 | { |
| 1335 | struct v4l2_jpegcompression *p=arg; |
| 1336 | if (!vfd->vidioc_g_jpegcomp) |
| 1337 | break; |
| 1338 | dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, " |
| 1339 | "COM_len=%d, jpeg_markers=%d\n", |
| 1340 | p->quality,p->APPn,p->APP_len, |
| 1341 | p->COM_len,p->jpeg_markers); |
| 1342 | ret=vfd->vidioc_s_jpegcomp(file, fh, p); |
| 1343 | break; |
| 1344 | } |
| 1345 | case VIDIOC_G_PARM: |
| 1346 | { |
| 1347 | struct v4l2_streamparm *p=arg; |
Mauro Carvalho Chehab | 1c2d034 | 2006-09-14 13:36:34 -0300 | [diff] [blame] | 1348 | if (vfd->vidioc_g_parm) { |
| 1349 | ret=vfd->vidioc_g_parm(file, fh, p); |
| 1350 | } else { |
| 1351 | struct v4l2_standard s; |
Mauro Carvalho Chehab | 1c2d034 | 2006-09-14 13:36:34 -0300 | [diff] [blame] | 1352 | |
| 1353 | if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1354 | return -EINVAL; |
| 1355 | |
Jonathan Corbet | 83427ac | 2006-10-13 07:51:16 -0300 | [diff] [blame] | 1356 | v4l2_video_std_construct(&s, vfd->current_norm, |
Mauro Carvalho Chehab | e75f9ce | 2006-11-20 13:19:20 -0300 | [diff] [blame] | 1357 | v4l2_norm_to_name(vfd->current_norm)); |
Mauro Carvalho Chehab | 1c2d034 | 2006-09-14 13:36:34 -0300 | [diff] [blame] | 1358 | |
| 1359 | memset(p,0,sizeof(*p)); |
| 1360 | |
| 1361 | p->parm.capture.timeperframe = s.frameperiod; |
| 1362 | ret=0; |
| 1363 | } |
| 1364 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1365 | dbgarg (cmd, "type=%d\n", p->type); |
| 1366 | break; |
| 1367 | } |
| 1368 | case VIDIOC_S_PARM: |
| 1369 | { |
| 1370 | struct v4l2_streamparm *p=arg; |
| 1371 | if (!vfd->vidioc_s_parm) |
| 1372 | break; |
| 1373 | dbgarg (cmd, "type=%d\n", p->type); |
| 1374 | ret=vfd->vidioc_s_parm(file, fh, p); |
| 1375 | break; |
| 1376 | } |
| 1377 | case VIDIOC_G_TUNER: |
| 1378 | { |
| 1379 | struct v4l2_tuner *p=arg; |
Mauro Carvalho Chehab | 7964b1b | 2006-11-20 12:10:43 -0300 | [diff] [blame] | 1380 | __u32 index=p->index; |
| 1381 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1382 | if (!vfd->vidioc_g_tuner) |
| 1383 | break; |
Mauro Carvalho Chehab | 7964b1b | 2006-11-20 12:10:43 -0300 | [diff] [blame] | 1384 | |
| 1385 | memset(p,0,sizeof(*p)); |
| 1386 | p->index=index; |
| 1387 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1388 | ret=vfd->vidioc_g_tuner(file, fh, p); |
| 1389 | if (!ret) |
| 1390 | dbgarg (cmd, "index=%d, name=%s, type=%d, " |
| 1391 | "capability=%d, rangelow=%d, " |
| 1392 | "rangehigh=%d, signal=%d, afc=%d, " |
| 1393 | "rxsubchans=%d, audmode=%d\n", |
| 1394 | p->index, p->name, p->type, |
| 1395 | p->capability, p->rangelow, |
| 1396 | p->rangehigh, p->rxsubchans, |
| 1397 | p->audmode, p->signal, p->afc); |
| 1398 | break; |
| 1399 | } |
| 1400 | case VIDIOC_S_TUNER: |
| 1401 | { |
| 1402 | struct v4l2_tuner *p=arg; |
| 1403 | if (!vfd->vidioc_s_tuner) |
| 1404 | break; |
| 1405 | dbgarg (cmd, "index=%d, name=%s, type=%d, " |
| 1406 | "capability=%d, rangelow=%d, rangehigh=%d, " |
| 1407 | "signal=%d, afc=%d, rxsubchans=%d, " |
| 1408 | "audmode=%d\n",p->index, p->name, p->type, |
| 1409 | p->capability, p->rangelow,p->rangehigh, |
| 1410 | p->rxsubchans, p->audmode, p->signal, |
| 1411 | p->afc); |
| 1412 | ret=vfd->vidioc_s_tuner(file, fh, p); |
| 1413 | break; |
| 1414 | } |
| 1415 | case VIDIOC_G_FREQUENCY: |
| 1416 | { |
| 1417 | struct v4l2_frequency *p=arg; |
| 1418 | if (!vfd->vidioc_g_frequency) |
| 1419 | break; |
Mauro Carvalho Chehab | 7964b1b | 2006-11-20 12:10:43 -0300 | [diff] [blame] | 1420 | |
| 1421 | memset(p,0,sizeof(*p)); |
| 1422 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1423 | ret=vfd->vidioc_g_frequency(file, fh, p); |
| 1424 | if (!ret) |
| 1425 | dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n", |
| 1426 | p->tuner,p->type,p->frequency); |
| 1427 | break; |
| 1428 | } |
| 1429 | case VIDIOC_S_FREQUENCY: |
| 1430 | { |
| 1431 | struct v4l2_frequency *p=arg; |
| 1432 | if (!vfd->vidioc_s_frequency) |
| 1433 | break; |
| 1434 | dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n", |
| 1435 | p->tuner,p->type,p->frequency); |
| 1436 | ret=vfd->vidioc_s_frequency(file, fh, p); |
| 1437 | break; |
| 1438 | } |
| 1439 | case VIDIOC_G_SLICED_VBI_CAP: |
| 1440 | { |
| 1441 | struct v4l2_sliced_vbi_cap *p=arg; |
| 1442 | if (!vfd->vidioc_g_sliced_vbi_cap) |
| 1443 | break; |
| 1444 | ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p); |
| 1445 | if (!ret) |
| 1446 | dbgarg (cmd, "service_set=%d\n", p->service_set); |
| 1447 | break; |
| 1448 | } |
| 1449 | case VIDIOC_LOG_STATUS: |
| 1450 | { |
| 1451 | if (!vfd->vidioc_log_status) |
| 1452 | break; |
| 1453 | ret=vfd->vidioc_log_status(file, fh); |
| 1454 | break; |
| 1455 | } |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1456 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
Trent Piepho | 52ebc76 | 2007-01-23 22:38:13 -0300 | [diff] [blame^] | 1457 | case VIDIOC_DBG_G_REGISTER: |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1458 | { |
| 1459 | struct v4l2_register *p=arg; |
| 1460 | if (vfd->vidioc_g_register) |
| 1461 | ret=vfd->vidioc_g_register(file, fh, p); |
| 1462 | break; |
| 1463 | } |
Trent Piepho | 52ebc76 | 2007-01-23 22:38:13 -0300 | [diff] [blame^] | 1464 | case VIDIOC_DBG_S_REGISTER: |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1465 | { |
| 1466 | struct v4l2_register *p=arg; |
Trent Piepho | 52ebc76 | 2007-01-23 22:38:13 -0300 | [diff] [blame^] | 1467 | if (!capable(CAP_SYS_ADMIN)) |
| 1468 | ret=-EPERM; |
| 1469 | else if (vfd->vidioc_s_register) |
Trent Piepho | dbbff48 | 2007-01-22 23:31:53 -0300 | [diff] [blame] | 1470 | ret=vfd->vidioc_s_register(file, fh, p); |
| 1471 | break; |
| 1472 | } |
| 1473 | #endif |
Mauro Carvalho Chehab | 207705c | 2006-11-20 12:13:25 -0300 | [diff] [blame] | 1474 | } /* switch */ |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1475 | |
| 1476 | if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { |
| 1477 | if (ret<0) { |
| 1478 | printk ("%s: err:\n", vfd->name); |
| 1479 | v4l_print_ioctl(vfd->name, cmd); |
| 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | return ret; |
| 1484 | } |
| 1485 | |
| 1486 | int video_ioctl2 (struct inode *inode, struct file *file, |
| 1487 | unsigned int cmd, unsigned long arg) |
| 1488 | { |
| 1489 | char sbuf[128]; |
| 1490 | void *mbuf = NULL; |
| 1491 | void *parg = NULL; |
| 1492 | int err = -EINVAL; |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 1493 | int is_ext_ctrl; |
| 1494 | size_t ctrls_size = 0; |
| 1495 | void __user *user_ptr = NULL; |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1496 | |
| 1497 | #ifdef __OLD_VIDIOC_ |
| 1498 | cmd = video_fix_command(cmd); |
| 1499 | #endif |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 1500 | is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS || |
| 1501 | cmd == VIDIOC_TRY_EXT_CTRLS); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1502 | |
| 1503 | /* Copy arguments into temp kernel buffer */ |
| 1504 | switch (_IOC_DIR(cmd)) { |
| 1505 | case _IOC_NONE: |
| 1506 | parg = NULL; |
| 1507 | break; |
| 1508 | case _IOC_READ: |
| 1509 | case _IOC_WRITE: |
| 1510 | case (_IOC_WRITE | _IOC_READ): |
| 1511 | if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { |
| 1512 | parg = sbuf; |
| 1513 | } else { |
| 1514 | /* too big to allocate from stack */ |
| 1515 | mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL); |
| 1516 | if (NULL == mbuf) |
| 1517 | return -ENOMEM; |
| 1518 | parg = mbuf; |
| 1519 | } |
| 1520 | |
| 1521 | err = -EFAULT; |
| 1522 | if (_IOC_DIR(cmd) & _IOC_WRITE) |
| 1523 | if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd))) |
| 1524 | goto out; |
| 1525 | break; |
| 1526 | } |
| 1527 | |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 1528 | if (is_ext_ctrl) { |
| 1529 | struct v4l2_ext_controls *p = parg; |
| 1530 | |
| 1531 | /* In case of an error, tell the caller that it wasn't |
| 1532 | a specific control that caused it. */ |
| 1533 | p->error_idx = p->count; |
| 1534 | user_ptr = (void __user *)p->controls; |
| 1535 | if (p->count) { |
| 1536 | ctrls_size = sizeof(struct v4l2_ext_control) * p->count; |
| 1537 | /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */ |
| 1538 | mbuf = kmalloc(ctrls_size, GFP_KERNEL); |
| 1539 | err = -ENOMEM; |
| 1540 | if (NULL == mbuf) |
| 1541 | goto out_ext_ctrl; |
| 1542 | err = -EFAULT; |
| 1543 | if (copy_from_user(mbuf, user_ptr, ctrls_size)) |
| 1544 | goto out_ext_ctrl; |
| 1545 | p->controls = mbuf; |
| 1546 | } |
| 1547 | } |
| 1548 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1549 | /* Handles IOCTL */ |
| 1550 | err = __video_do_ioctl(inode, file, cmd, parg); |
| 1551 | if (err == -ENOIOCTLCMD) |
| 1552 | err = -EINVAL; |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 1553 | if (is_ext_ctrl) { |
| 1554 | struct v4l2_ext_controls *p = parg; |
| 1555 | |
| 1556 | p->controls = (void *)user_ptr; |
| 1557 | if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size)) |
| 1558 | err = -EFAULT; |
| 1559 | goto out_ext_ctrl; |
| 1560 | } |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1561 | if (err < 0) |
| 1562 | goto out; |
| 1563 | |
Hans Verkuil | 0597691 | 2006-06-18 13:43:28 -0300 | [diff] [blame] | 1564 | out_ext_ctrl: |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1565 | /* Copy results into user buffer */ |
| 1566 | switch (_IOC_DIR(cmd)) |
| 1567 | { |
| 1568 | case _IOC_READ: |
| 1569 | case (_IOC_WRITE | _IOC_READ): |
| 1570 | if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd))) |
| 1571 | err = -EFAULT; |
| 1572 | break; |
| 1573 | } |
| 1574 | |
| 1575 | out: |
| 1576 | kfree(mbuf); |
| 1577 | return err; |
| 1578 | } |
| 1579 | |
| 1580 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 1581 | static const struct file_operations video_fops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
| 1583 | /** |
| 1584 | * video_register_device - register video4linux devices |
| 1585 | * @vfd: video device structure we want to register |
| 1586 | * @type: type of device to register |
| 1587 | * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ... |
| 1588 | * -1 == first free) |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 1589 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | * The registration code assigns minor numbers based on the type |
| 1591 | * requested. -ENFILE is returned in all the device slots for this |
| 1592 | * category are full. If not then the minor field is set and the |
| 1593 | * driver initialize function is called (if non %NULL). |
| 1594 | * |
| 1595 | * Zero is returned on success. |
| 1596 | * |
| 1597 | * Valid types are |
| 1598 | * |
| 1599 | * %VFL_TYPE_GRABBER - A frame grabber |
| 1600 | * |
| 1601 | * %VFL_TYPE_VTX - A teletext device |
| 1602 | * |
| 1603 | * %VFL_TYPE_VBI - Vertical blank data (undecoded) |
| 1604 | * |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 1605 | * %VFL_TYPE_RADIO - A radio card |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | */ |
| 1607 | |
| 1608 | int video_register_device(struct video_device *vfd, int type, int nr) |
| 1609 | { |
| 1610 | int i=0; |
| 1611 | int base; |
| 1612 | int end; |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 1613 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | char *name_base; |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 1615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | switch(type) |
| 1617 | { |
| 1618 | case VFL_TYPE_GRABBER: |
Mauro Carvalho Chehab | 4d0dddb | 2006-01-23 17:11:07 -0200 | [diff] [blame] | 1619 | base=MINOR_VFL_TYPE_GRABBER_MIN; |
| 1620 | end=MINOR_VFL_TYPE_GRABBER_MAX+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | name_base = "video"; |
| 1622 | break; |
| 1623 | case VFL_TYPE_VTX: |
Mauro Carvalho Chehab | 4d0dddb | 2006-01-23 17:11:07 -0200 | [diff] [blame] | 1624 | base=MINOR_VFL_TYPE_VTX_MIN; |
| 1625 | end=MINOR_VFL_TYPE_VTX_MAX+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | name_base = "vtx"; |
| 1627 | break; |
| 1628 | case VFL_TYPE_VBI: |
Mauro Carvalho Chehab | 4d0dddb | 2006-01-23 17:11:07 -0200 | [diff] [blame] | 1629 | base=MINOR_VFL_TYPE_VBI_MIN; |
| 1630 | end=MINOR_VFL_TYPE_VBI_MAX+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | name_base = "vbi"; |
| 1632 | break; |
| 1633 | case VFL_TYPE_RADIO: |
Mauro Carvalho Chehab | 4d0dddb | 2006-01-23 17:11:07 -0200 | [diff] [blame] | 1634 | base=MINOR_VFL_TYPE_RADIO_MIN; |
| 1635 | end=MINOR_VFL_TYPE_RADIO_MAX+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | name_base = "radio"; |
| 1637 | break; |
| 1638 | default: |
Trent Piepho | 53dd8de | 2006-07-25 09:31:42 -0300 | [diff] [blame] | 1639 | printk(KERN_ERR "%s called with unknown type: %d\n", |
| 1640 | __FUNCTION__, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | return -1; |
| 1642 | } |
| 1643 | |
| 1644 | /* pick a minor number */ |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 1645 | mutex_lock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | if (nr >= 0 && nr < end-base) { |
| 1647 | /* use the one the driver asked for */ |
| 1648 | i = base+nr; |
| 1649 | if (NULL != video_device[i]) { |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 1650 | mutex_unlock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | return -ENFILE; |
| 1652 | } |
| 1653 | } else { |
| 1654 | /* use first free */ |
| 1655 | for(i=base;i<end;i++) |
| 1656 | if (NULL == video_device[i]) |
| 1657 | break; |
| 1658 | if (i == end) { |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 1659 | mutex_unlock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | return -ENFILE; |
| 1661 | } |
| 1662 | } |
| 1663 | video_device[i]=vfd; |
| 1664 | vfd->minor=i; |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 1665 | mutex_unlock(&videodev_lock); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1666 | mutex_init(&vfd->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | |
| 1668 | /* sysfs class */ |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 1669 | memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | if (vfd->dev) |
| 1671 | vfd->class_dev.dev = vfd->dev; |
| 1672 | vfd->class_dev.class = &video_class; |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 1673 | vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); |
Greg Kroah-Hartman | 5e48307 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 1674 | sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base); |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 1675 | ret = class_device_register(&vfd->class_dev); |
Trent Piepho | 8c31311 | 2006-07-25 20:37:03 -0300 | [diff] [blame] | 1676 | if (ret < 0) { |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 1677 | printk(KERN_ERR "%s: class_device_register failed\n", |
| 1678 | __FUNCTION__); |
Trent Piepho | d94fc9a | 2006-07-29 17:18:06 -0300 | [diff] [blame] | 1679 | goto fail_minor; |
Michael Krufky | 3117bee | 2006-07-19 13:23:38 -0300 | [diff] [blame] | 1680 | } |
Mauro Carvalho Chehab | 985bc96 | 2006-07-23 06:31:19 -0300 | [diff] [blame] | 1681 | ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name); |
| 1682 | if (ret < 0) { |
Trent Piepho | d94fc9a | 2006-07-29 17:18:06 -0300 | [diff] [blame] | 1683 | printk(KERN_ERR "%s: class_device_create_file 'name' failed\n", |
| 1684 | __FUNCTION__); |
| 1685 | goto fail_classdev; |
Mauro Carvalho Chehab | 985bc96 | 2006-07-23 06:31:19 -0300 | [diff] [blame] | 1686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | |
Mauro Carvalho Chehab | d21838d | 2006-01-09 15:25:21 -0200 | [diff] [blame] | 1688 | #if 1 |
| 1689 | /* needed until all drivers are fixed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | if (!vfd->release) |
| 1691 | printk(KERN_WARNING "videodev: \"%s\" has no release callback. " |
| 1692 | "Please fix your driver for proper sysfs support, see " |
| 1693 | "http://lwn.net/Articles/36850/\n", vfd->name); |
| 1694 | #endif |
| 1695 | return 0; |
Trent Piepho | 53dd8de | 2006-07-25 09:31:42 -0300 | [diff] [blame] | 1696 | |
| 1697 | fail_classdev: |
| 1698 | class_device_unregister(&vfd->class_dev); |
| 1699 | fail_minor: |
| 1700 | mutex_lock(&videodev_lock); |
| 1701 | video_device[vfd->minor] = NULL; |
| 1702 | vfd->minor = -1; |
| 1703 | mutex_unlock(&videodev_lock); |
| 1704 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * video_unregister_device - unregister a video4linux device |
| 1709 | * @vfd: the device to unregister |
| 1710 | * |
| 1711 | * This unregisters the passed device and deassigns the minor |
| 1712 | * number. Future open calls will be met with errors. |
| 1713 | */ |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 1714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | void video_unregister_device(struct video_device *vfd) |
| 1716 | { |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 1717 | mutex_lock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | if(video_device[vfd->minor]!=vfd) |
| 1719 | panic("videodev: bad unregister"); |
| 1720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | video_device[vfd->minor]=NULL; |
| 1722 | class_device_unregister(&vfd->class_dev); |
Ingo Molnar | 1e4baed | 2006-01-15 07:52:23 -0200 | [diff] [blame] | 1723 | mutex_unlock(&videodev_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1726 | /* |
| 1727 | * Video fs operations |
| 1728 | */ |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 1729 | static const struct file_operations video_fops= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | { |
| 1731 | .owner = THIS_MODULE, |
| 1732 | .llseek = no_llseek, |
| 1733 | .open = video_open, |
| 1734 | }; |
| 1735 | |
| 1736 | /* |
| 1737 | * Initialise video for linux |
| 1738 | */ |
Sigmund Augdal Helberg | 938606b | 2005-12-01 00:51:19 -0800 | [diff] [blame] | 1739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | static int __init videodev_init(void) |
| 1741 | { |
| 1742 | int ret; |
| 1743 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1744 | printk(KERN_INFO "Linux video capture interface: v2.00\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) { |
| 1746 | printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR); |
| 1747 | return -EIO; |
| 1748 | } |
| 1749 | |
| 1750 | ret = class_register(&video_class); |
| 1751 | if (ret < 0) { |
| 1752 | unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME); |
| 1753 | printk(KERN_WARNING "video_dev: class_register failed\n"); |
| 1754 | return -EIO; |
| 1755 | } |
| 1756 | |
| 1757 | return 0; |
| 1758 | } |
| 1759 | |
| 1760 | static void __exit videodev_exit(void) |
| 1761 | { |
| 1762 | class_unregister(&video_class); |
| 1763 | unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME); |
| 1764 | } |
| 1765 | |
| 1766 | module_init(videodev_init) |
| 1767 | module_exit(videodev_exit) |
| 1768 | |
| 1769 | EXPORT_SYMBOL(video_register_device); |
| 1770 | EXPORT_SYMBOL(video_unregister_device); |
| 1771 | EXPORT_SYMBOL(video_devdata); |
| 1772 | EXPORT_SYMBOL(video_usercopy); |
| 1773 | EXPORT_SYMBOL(video_exclusive_open); |
| 1774 | EXPORT_SYMBOL(video_exclusive_release); |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1775 | EXPORT_SYMBOL(video_ioctl2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | EXPORT_SYMBOL(video_device_alloc); |
| 1777 | EXPORT_SYMBOL(video_device_release); |
| 1778 | |
Mauro Carvalho Chehab | 401998f | 2006-06-04 10:06:18 -0300 | [diff] [blame] | 1779 | MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 1780 | MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | MODULE_LICENSE("GPL"); |
| 1782 | |
| 1783 | |
| 1784 | /* |
| 1785 | * Local variables: |
| 1786 | * c-basic-offset: 8 |
| 1787 | * End: |
| 1788 | */ |