blob: 9024ea2557fd61570fe7f1779cfcb308358300b6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03002 * Video capture interface for Linux version 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03004 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03007 * 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 Torvalds1da177e2005-04-16 15:20:36 -070011 *
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030012 * Authors: Alan Cox, <alan@redhat.com> (version 1)
13 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
15 * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
16 * - Added procfs support
17 */
18
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030019#define dbgarg(cmd, fmt, arg...) \
Enrico Scholz474ce782006-10-09 16:27:05 -030020 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030021 printk (KERN_DEBUG "%s: ", vfd->name); \
22 v4l_printk_ioctl(cmd); \
Enrico Scholz474ce782006-10-09 16:27:05 -030023 printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); \
24 }
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030025
26#define dbgarg2(fmt, arg...) \
27 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
28 printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg);
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/types.h>
32#include <linux/kernel.h>
33#include <linux/sched.h>
34#include <linux/smp_lock.h>
35#include <linux/mm.h>
36#include <linux/string.h>
37#include <linux/errno.h>
38#include <linux/init.h>
39#include <linux/kmod.h>
40#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/uaccess.h>
42#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030044#define __OLD_VIDIOC_ /* To allow fixing old calls*/
45#include <linux/videodev2.h>
46
47#ifdef CONFIG_VIDEO_V4L1
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/videodev.h>
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030049#endif
50#include <media/v4l2-common.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#define VIDEO_NUM_DEVICES 256
53#define VIDEO_NAME "video4linux"
54
55/*
56 * sysfs stuff
57 */
58
59static ssize_t show_name(struct class_device *cd, char *buf)
60{
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030061 struct video_device *vfd = container_of(cd, struct video_device,
62 class_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name);
64}
65
66static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
67
68struct video_device *video_device_alloc(void)
69{
70 struct video_device *vfd;
71
Panagiotis Issaris74081872006-01-11 19:40:56 -020072 vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 return vfd;
74}
75
76void video_device_release(struct video_device *vfd)
77{
78 kfree(vfd);
79}
80
81static void video_release(struct class_device *cd)
82{
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -030083 struct video_device *vfd = container_of(cd, struct video_device,
84 class_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Mauro Carvalho Chehabd21838d2006-01-09 15:25:21 -020086#if 1
Michael Krufky50c25ff2006-01-09 15:25:34 -020087 /* needed until all drivers are fixed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 if (!vfd->release)
89 return;
90#endif
91 vfd->release(vfd);
92}
93
94static struct class video_class = {
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -080095 .name = VIDEO_NAME,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 .release = video_release,
97};
98
99/*
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -0800100 * Active devices
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 */
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -0800102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static struct video_device *video_device[VIDEO_NUM_DEVICES];
Ingo Molnar1e4baed2006-01-15 07:52:23 -0200104static DEFINE_MUTEX(videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106struct video_device* video_devdata(struct file *file)
107{
Josef Sipek723731b2006-12-08 02:37:47 -0800108 return video_device[iminor(file->f_path.dentry->d_inode)];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
111/*
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300112 * Open a video device - FIXME: Obsoleted
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 */
114static int video_open(struct inode *inode, struct file *file)
115{
116 unsigned int minor = iminor(inode);
117 int err = 0;
118 struct video_device *vfl;
Arjan van de Ven99ac48f2006-03-28 01:56:41 -0800119 const struct file_operations *old_fops;
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -0800120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if(minor>=VIDEO_NUM_DEVICES)
122 return -ENODEV;
Ingo Molnar1e4baed2006-01-15 07:52:23 -0200123 mutex_lock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 vfl=video_device[minor];
125 if(vfl==NULL) {
Ingo Molnar1e4baed2006-01-15 07:52:23 -0200126 mutex_unlock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
Ingo Molnar1e4baed2006-01-15 07:52:23 -0200128 mutex_lock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 vfl=video_device[minor];
130 if (vfl==NULL) {
Ingo Molnar1e4baed2006-01-15 07:52:23 -0200131 mutex_unlock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return -ENODEV;
133 }
134 }
135 old_fops = file->f_op;
136 file->f_op = fops_get(vfl->fops);
137 if(file->f_op->open)
138 err = file->f_op->open(inode,file);
139 if (err) {
140 fops_put(file->f_op);
141 file->f_op = fops_get(old_fops);
142 }
143 fops_put(old_fops);
Ingo Molnar1e4baed2006-01-15 07:52:23 -0200144 mutex_unlock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return err;
146}
147
148/*
149 * helper function -- handles userspace copying for ioctl arguments
150 */
151
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300152#ifdef __OLD_VIDIOC_
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153static unsigned int
154video_fix_command(unsigned int cmd)
155{
156 switch (cmd) {
157 case VIDIOC_OVERLAY_OLD:
158 cmd = VIDIOC_OVERLAY;
159 break;
160 case VIDIOC_S_PARM_OLD:
161 cmd = VIDIOC_S_PARM;
162 break;
163 case VIDIOC_S_CTRL_OLD:
164 cmd = VIDIOC_S_CTRL;
165 break;
166 case VIDIOC_G_AUDIO_OLD:
167 cmd = VIDIOC_G_AUDIO;
168 break;
169 case VIDIOC_G_AUDOUT_OLD:
170 cmd = VIDIOC_G_AUDOUT;
171 break;
172 case VIDIOC_CROPCAP_OLD:
173 cmd = VIDIOC_CROPCAP;
174 break;
175 }
176 return cmd;
177}
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300178#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300180/*
181 * Obsolete usercopy function - Should be removed soon
182 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183int
184video_usercopy(struct inode *inode, struct file *file,
185 unsigned int cmd, unsigned long arg,
186 int (*func)(struct inode *inode, struct file *file,
187 unsigned int cmd, void *arg))
188{
189 char sbuf[128];
190 void *mbuf = NULL;
191 void *parg = NULL;
192 int err = -EINVAL;
Hans Verkuil05976912006-06-18 13:43:28 -0300193 int is_ext_ctrl;
194 size_t ctrls_size = 0;
195 void __user *user_ptr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300197#ifdef __OLD_VIDIOC_
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 cmd = video_fix_command(cmd);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300199#endif
Hans Verkuil05976912006-06-18 13:43:28 -0300200 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
201 cmd == VIDIOC_TRY_EXT_CTRLS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 /* Copy arguments into temp kernel buffer */
204 switch (_IOC_DIR(cmd)) {
205 case _IOC_NONE:
206 parg = NULL;
207 break;
208 case _IOC_READ:
209 case _IOC_WRITE:
210 case (_IOC_WRITE | _IOC_READ):
211 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
212 parg = sbuf;
213 } else {
214 /* too big to allocate from stack */
215 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
216 if (NULL == mbuf)
217 return -ENOMEM;
218 parg = mbuf;
219 }
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -0800220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 err = -EFAULT;
222 if (_IOC_DIR(cmd) & _IOC_WRITE)
Hans Verkuil05976912006-06-18 13:43:28 -0300223 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 goto out;
225 break;
226 }
Hans Verkuil05976912006-06-18 13:43:28 -0300227 if (is_ext_ctrl) {
228 struct v4l2_ext_controls *p = parg;
229
230 /* In case of an error, tell the caller that it wasn't
231 a specific control that caused it. */
232 p->error_idx = p->count;
233 user_ptr = (void __user *)p->controls;
234 if (p->count) {
235 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
236 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
237 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
238 err = -ENOMEM;
239 if (NULL == mbuf)
240 goto out_ext_ctrl;
241 err = -EFAULT;
242 if (copy_from_user(mbuf, user_ptr, ctrls_size))
243 goto out_ext_ctrl;
244 p->controls = mbuf;
245 }
246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 /* call driver */
249 err = func(inode, file, cmd, parg);
250 if (err == -ENOIOCTLCMD)
251 err = -EINVAL;
Hans Verkuil05976912006-06-18 13:43:28 -0300252 if (is_ext_ctrl) {
253 struct v4l2_ext_controls *p = parg;
254
255 p->controls = (void *)user_ptr;
256 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
257 err = -EFAULT;
258 goto out_ext_ctrl;
259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (err < 0)
261 goto out;
262
Hans Verkuil05976912006-06-18 13:43:28 -0300263out_ext_ctrl:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* Copy results into user buffer */
265 switch (_IOC_DIR(cmd))
266 {
267 case _IOC_READ:
268 case (_IOC_WRITE | _IOC_READ):
269 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
270 err = -EFAULT;
271 break;
272 }
273
274out:
Jesper Juhl2ea75332005-11-07 01:01:31 -0800275 kfree(mbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return err;
277}
278
279/*
280 * open/release helper functions -- handle exclusive opens
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300281 * Should be removed soon
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 */
283int video_exclusive_open(struct inode *inode, struct file *file)
284{
285 struct video_device *vfl = video_devdata(file);
286 int retval = 0;
287
Ingo Molnar3593cab2006-02-07 06:49:14 -0200288 mutex_lock(&vfl->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (vfl->users) {
290 retval = -EBUSY;
291 } else {
292 vfl->users++;
293 }
Ingo Molnar3593cab2006-02-07 06:49:14 -0200294 mutex_unlock(&vfl->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 return retval;
296}
297
298int video_exclusive_release(struct inode *inode, struct file *file)
299{
300 struct video_device *vfl = video_devdata(file);
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -0800301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 vfl->users--;
303 return 0;
304}
305
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300306static char *v4l2_memory_names[] = {
307 [V4L2_MEMORY_MMAP] = "mmap",
308 [V4L2_MEMORY_USERPTR] = "userptr",
309 [V4L2_MEMORY_OVERLAY] = "overlay",
310};
311
312
313/* FIXME: Those stuff are replicated also on v4l2-common.c */
314static char *v4l2_type_names_FIXME[] = {
315 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
316 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
317 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
318 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
319 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
320 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
321 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-capture",
322 [V4L2_BUF_TYPE_PRIVATE] = "private",
323};
324
325static char *v4l2_field_names_FIXME[] = {
326 [V4L2_FIELD_ANY] = "any",
327 [V4L2_FIELD_NONE] = "none",
328 [V4L2_FIELD_TOP] = "top",
329 [V4L2_FIELD_BOTTOM] = "bottom",
330 [V4L2_FIELD_INTERLACED] = "interlaced",
331 [V4L2_FIELD_SEQ_TB] = "seq-tb",
332 [V4L2_FIELD_SEQ_BT] = "seq-bt",
333 [V4L2_FIELD_ALTERNATE] = "alternate",
334};
335
336#define prt_names(a,arr) (((a)>=0)&&((a)<ARRAY_SIZE(arr)))?arr[a]:"unknown"
337
338static void dbgbuf(unsigned int cmd, struct video_device *vfd,
339 struct v4l2_buffer *p)
340{
341 struct v4l2_timecode *tc=&p->timecode;
342
343 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
344 "bytesused=%d, flags=0x%08d, "
345 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n",
346 (p->timestamp.tv_sec/3600),
347 (int)(p->timestamp.tv_sec/60)%60,
348 (int)(p->timestamp.tv_sec%60),
349 p->timestamp.tv_usec,
350 p->index,
351 prt_names(p->type,v4l2_type_names_FIXME),
352 p->bytesused,p->flags,
353 p->field,p->sequence,
354 prt_names(p->memory,v4l2_memory_names),
355 p->m.userptr);
356 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
357 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
358 tc->hours,tc->minutes,tc->seconds,
Mauro Carvalho Chehabc18cb012006-06-23 07:05:22 -0300359 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300360}
361
362static inline void dbgrect(struct video_device *vfd, char *s,
363 struct v4l2_rect *r)
364{
365 dbgarg2 ("%sRect start at %dx%d, size= %dx%d\n", s, r->left, r->top,
366 r->width, r->height);
367};
368
369static inline void v4l_print_pix_fmt (struct video_device *vfd,
370 struct v4l2_pix_format *fmt)
371{
372 dbgarg2 ("width=%d, height=%d, format=0x%08x, field=%s, "
373 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
374 fmt->width,fmt->height,fmt->pixelformat,
375 prt_names(fmt->field,v4l2_field_names_FIXME),
376 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
377};
378
379
380static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
381{
382 switch (type) {
383 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
384 if (vfd->vidioc_try_fmt_cap)
385 return (0);
386 break;
387 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
388 if (vfd->vidioc_try_fmt_overlay)
389 return (0);
390 break;
391 case V4L2_BUF_TYPE_VBI_CAPTURE:
392 if (vfd->vidioc_try_fmt_vbi)
393 return (0);
394 break;
395 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
396 if (vfd->vidioc_try_fmt_vbi_output)
397 return (0);
398 break;
399 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
400 if (vfd->vidioc_try_fmt_vbi_capture)
401 return (0);
402 break;
403 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
404 if (vfd->vidioc_try_fmt_video_output)
405 return (0);
406 break;
407 case V4L2_BUF_TYPE_VBI_OUTPUT:
408 if (vfd->vidioc_try_fmt_vbi_output)
409 return (0);
410 break;
411 case V4L2_BUF_TYPE_PRIVATE:
412 if (vfd->vidioc_try_fmt_type_private)
413 return (0);
414 break;
415 }
416 return (-EINVAL);
417}
418
419static int __video_do_ioctl(struct inode *inode, struct file *file,
420 unsigned int cmd, void *arg)
421{
422 struct video_device *vfd = video_devdata(file);
423 void *fh = file->private_data;
424 int ret = -EINVAL;
425
426 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
427 !(vfd->debug | V4L2_DEBUG_IOCTL_ARG)) {
428 v4l_print_ioctl(vfd->name, cmd);
429 }
430
431 switch(cmd) {
432 /* --- capabilities ------------------------------------------ */
433 case VIDIOC_QUERYCAP:
434 {
435 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
436 memset(cap, 0, sizeof(*cap));
437
438 if (!vfd->vidioc_querycap)
439 break;
440
441 ret=vfd->vidioc_querycap(file, fh, cap);
442 if (!ret)
443 dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
444 "version=0x%08x, "
445 "capabilities=0x%08x\n",
446 cap->driver,cap->card,cap->bus_info,
447 cap->version,
448 cap->capabilities);
449 break;
450 }
451
452 /* --- priority ------------------------------------------ */
453 case VIDIOC_G_PRIORITY:
454 {
455 enum v4l2_priority *p=arg;
456
457 if (!vfd->vidioc_g_priority)
458 break;
459 ret=vfd->vidioc_g_priority(file, fh, p);
460 if (!ret)
461 dbgarg(cmd, "priority is %d\n", *p);
462 break;
463 }
464 case VIDIOC_S_PRIORITY:
465 {
466 enum v4l2_priority *p=arg;
467
468 if (!vfd->vidioc_s_priority)
469 break;
470 dbgarg(cmd, "setting priority to %d\n", *p);
471 ret=vfd->vidioc_s_priority(file, fh, *p);
472 break;
473 }
474
475 /* --- capture ioctls ---------------------------------------- */
476 case VIDIOC_ENUM_FMT:
477 {
478 struct v4l2_fmtdesc *f = arg;
479 enum v4l2_buf_type type;
480 unsigned int index;
481
482 index = f->index;
483 type = f->type;
484 memset(f,0,sizeof(*f));
485 f->index = index;
486 f->type = type;
487
488 switch (type) {
489 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
490 if (vfd->vidioc_enum_fmt_cap)
491 ret=vfd->vidioc_enum_fmt_cap(file, fh, f);
492 break;
493 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
494 if (vfd->vidioc_enum_fmt_overlay)
495 ret=vfd->vidioc_enum_fmt_overlay(file, fh, f);
496 break;
497 case V4L2_BUF_TYPE_VBI_CAPTURE:
498 if (vfd->vidioc_enum_fmt_vbi)
499 ret=vfd->vidioc_enum_fmt_vbi(file, fh, f);
500 break;
501 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
502 if (vfd->vidioc_enum_fmt_vbi_output)
503 ret=vfd->vidioc_enum_fmt_vbi_output(file,
504 fh, f);
505 break;
506 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
507 if (vfd->vidioc_enum_fmt_vbi_capture)
508 ret=vfd->vidioc_enum_fmt_vbi_capture(file,
509 fh, f);
510 break;
511 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
512 if (vfd->vidioc_enum_fmt_video_output)
513 ret=vfd->vidioc_enum_fmt_video_output(file,
514 fh, f);
515 break;
516 case V4L2_BUF_TYPE_VBI_OUTPUT:
517 if (vfd->vidioc_enum_fmt_vbi_output)
518 ret=vfd->vidioc_enum_fmt_vbi_output(file,
519 fh, f);
520 break;
521 case V4L2_BUF_TYPE_PRIVATE:
522 if (vfd->vidioc_enum_fmt_type_private)
523 ret=vfd->vidioc_enum_fmt_type_private(file,
524 fh, f);
525 break;
526 }
527 if (!ret)
528 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
529 "description=%s,"
530 " pixelformat=0x%8x\n",
531 f->index, f->type, f->flags,
532 f->description,
533 f->pixelformat);
534
535 break;
536 }
537 case VIDIOC_G_FMT:
538 {
539 struct v4l2_format *f = (struct v4l2_format *)arg;
540 enum v4l2_buf_type type=f->type;
541
542 memset(&f->fmt.pix,0,sizeof(f->fmt.pix));
543 f->type=type;
544
545 /* FIXME: Should be one dump per type */
546 dbgarg (cmd, "type=%s\n", prt_names(type,
547 v4l2_type_names_FIXME));
548
549 switch (type) {
550 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
551 if (vfd->vidioc_g_fmt_cap)
552 ret=vfd->vidioc_g_fmt_cap(file, fh, f);
553 if (!ret)
554 v4l_print_pix_fmt(vfd,&f->fmt.pix);
555 break;
556 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
557 if (vfd->vidioc_g_fmt_overlay)
558 ret=vfd->vidioc_g_fmt_overlay(file, fh, f);
559 break;
560 case V4L2_BUF_TYPE_VBI_CAPTURE:
561 if (vfd->vidioc_g_fmt_vbi)
562 ret=vfd->vidioc_g_fmt_vbi(file, fh, f);
563 break;
564 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
565 if (vfd->vidioc_g_fmt_vbi_output)
566 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
567 break;
568 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
569 if (vfd->vidioc_g_fmt_vbi_capture)
570 ret=vfd->vidioc_g_fmt_vbi_capture(file, fh, f);
571 break;
572 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
573 if (vfd->vidioc_g_fmt_video_output)
574 ret=vfd->vidioc_g_fmt_video_output(file,
575 fh, f);
576 break;
577 case V4L2_BUF_TYPE_VBI_OUTPUT:
578 if (vfd->vidioc_g_fmt_vbi_output)
579 ret=vfd->vidioc_g_fmt_vbi_output(file, fh, f);
580 break;
581 case V4L2_BUF_TYPE_PRIVATE:
582 if (vfd->vidioc_g_fmt_type_private)
583 ret=vfd->vidioc_g_fmt_type_private(file,
584 fh, f);
585 break;
586 }
587
588 break;
589 }
590 case VIDIOC_S_FMT:
591 {
592 struct v4l2_format *f = (struct v4l2_format *)arg;
593
594 /* FIXME: Should be one dump per type */
595 dbgarg (cmd, "type=%s\n", prt_names(f->type,
596 v4l2_type_names_FIXME));
597
598 switch (f->type) {
599 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
600 v4l_print_pix_fmt(vfd,&f->fmt.pix);
601 if (vfd->vidioc_s_fmt_cap)
602 ret=vfd->vidioc_s_fmt_cap(file, fh, f);
603 break;
604 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
605 if (vfd->vidioc_s_fmt_overlay)
606 ret=vfd->vidioc_s_fmt_overlay(file, fh, f);
607 break;
608 case V4L2_BUF_TYPE_VBI_CAPTURE:
609 if (vfd->vidioc_s_fmt_vbi)
610 ret=vfd->vidioc_s_fmt_vbi(file, fh, f);
611 break;
612 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
613 if (vfd->vidioc_s_fmt_vbi_output)
614 ret=vfd->vidioc_s_fmt_vbi_output(file, fh, f);
615 break;
616 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
617 if (vfd->vidioc_s_fmt_vbi_capture)
618 ret=vfd->vidioc_s_fmt_vbi_capture(file, fh, f);
619 break;
620 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
621 if (vfd->vidioc_s_fmt_video_output)
622 ret=vfd->vidioc_s_fmt_video_output(file,
623 fh, f);
624 break;
625 case V4L2_BUF_TYPE_VBI_OUTPUT:
626 if (vfd->vidioc_s_fmt_vbi_output)
627 ret=vfd->vidioc_s_fmt_vbi_output(file,
628 fh, f);
629 break;
630 case V4L2_BUF_TYPE_PRIVATE:
631 if (vfd->vidioc_s_fmt_type_private)
632 ret=vfd->vidioc_s_fmt_type_private(file,
633 fh, f);
634 break;
635 }
636 break;
637 }
638 case VIDIOC_TRY_FMT:
639 {
640 struct v4l2_format *f = (struct v4l2_format *)arg;
641
642 /* FIXME: Should be one dump per type */
643 dbgarg (cmd, "type=%s\n", prt_names(f->type,
644 v4l2_type_names_FIXME));
645 switch (f->type) {
646 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
647 if (vfd->vidioc_try_fmt_cap)
648 ret=vfd->vidioc_try_fmt_cap(file, fh, f);
649 if (!ret)
650 v4l_print_pix_fmt(vfd,&f->fmt.pix);
651 break;
652 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
653 if (vfd->vidioc_try_fmt_overlay)
654 ret=vfd->vidioc_try_fmt_overlay(file, fh, f);
655 break;
656 case V4L2_BUF_TYPE_VBI_CAPTURE:
657 if (vfd->vidioc_try_fmt_vbi)
658 ret=vfd->vidioc_try_fmt_vbi(file, fh, f);
659 break;
660 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
661 if (vfd->vidioc_try_fmt_vbi_output)
662 ret=vfd->vidioc_try_fmt_vbi_output(file,
663 fh, f);
664 break;
665 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
666 if (vfd->vidioc_try_fmt_vbi_capture)
667 ret=vfd->vidioc_try_fmt_vbi_capture(file,
668 fh, f);
669 break;
670 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
671 if (vfd->vidioc_try_fmt_video_output)
672 ret=vfd->vidioc_try_fmt_video_output(file,
673 fh, f);
674 break;
675 case V4L2_BUF_TYPE_VBI_OUTPUT:
676 if (vfd->vidioc_try_fmt_vbi_output)
677 ret=vfd->vidioc_try_fmt_vbi_output(file,
678 fh, f);
679 break;
680 case V4L2_BUF_TYPE_PRIVATE:
681 if (vfd->vidioc_try_fmt_type_private)
682 ret=vfd->vidioc_try_fmt_type_private(file,
683 fh, f);
684 break;
685 }
686
687 break;
688 }
689 /* FIXME: Those buf reqs could be handled here,
690 with some changes on videobuf to allow its header to be included at
691 videodev2.h or being merged at videodev2.
692 */
693 case VIDIOC_REQBUFS:
694 {
695 struct v4l2_requestbuffers *p=arg;
696
697 if (!vfd->vidioc_reqbufs)
698 break;
699 ret = check_fmt (vfd, p->type);
700 if (ret)
701 break;
702
703 ret=vfd->vidioc_reqbufs(file, fh, p);
704 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
705 p->count,
706 prt_names(p->type,v4l2_type_names_FIXME),
707 prt_names(p->memory,v4l2_memory_names));
708 break;
709 }
710 case VIDIOC_QUERYBUF:
711 {
712 struct v4l2_buffer *p=arg;
713
714 if (!vfd->vidioc_querybuf)
715 break;
716 ret = check_fmt (vfd, p->type);
717 if (ret)
718 break;
719
720 ret=vfd->vidioc_querybuf(file, fh, p);
721 if (!ret)
722 dbgbuf(cmd,vfd,p);
723 break;
724 }
725 case VIDIOC_QBUF:
726 {
727 struct v4l2_buffer *p=arg;
728
729 if (!vfd->vidioc_qbuf)
730 break;
731 ret = check_fmt (vfd, p->type);
732 if (ret)
733 break;
734
735 ret=vfd->vidioc_qbuf(file, fh, p);
736 if (!ret)
737 dbgbuf(cmd,vfd,p);
738 break;
739 }
740 case VIDIOC_DQBUF:
741 {
742 struct v4l2_buffer *p=arg;
Sascha Hauerc93a5c32006-09-11 09:49:19 -0300743 if (!vfd->vidioc_dqbuf)
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300744 break;
745 ret = check_fmt (vfd, p->type);
746 if (ret)
747 break;
748
Sascha Hauerc93a5c32006-09-11 09:49:19 -0300749 ret=vfd->vidioc_dqbuf(file, fh, p);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300750 if (!ret)
751 dbgbuf(cmd,vfd,p);
752 break;
753 }
754 case VIDIOC_OVERLAY:
755 {
756 int *i = arg;
757
758 if (!vfd->vidioc_overlay)
759 break;
760 dbgarg (cmd, "value=%d\n",*i);
761 ret=vfd->vidioc_overlay(file, fh, *i);
762 break;
763 }
Mauro Carvalho Chehab0dfa9ab2006-08-08 09:10:10 -0300764#ifdef CONFIG_VIDEO_V4L1_COMPAT
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300765 /* --- streaming capture ------------------------------------- */
766 case VIDIOCGMBUF:
767 {
768 struct video_mbuf *p=arg;
769
Mauro Carvalho Chehab4ceb04e2006-06-17 08:52:30 -0300770 memset(p,0,sizeof(p));
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300771
772 if (!vfd->vidiocgmbuf)
773 break;
774 ret=vfd->vidiocgmbuf(file, fh, p);
775 if (!ret)
776 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
777 p->size, p->frames,
778 (unsigned long)p->offsets);
779 break;
780 }
781#endif
782 case VIDIOC_G_FBUF:
783 {
784 struct v4l2_framebuffer *p=arg;
785 if (!vfd->vidioc_g_fbuf)
786 break;
787 ret=vfd->vidioc_g_fbuf(file, fh, arg);
788 if (!ret) {
789 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
790 p->capability,p->flags,
791 (unsigned long)p->base);
792 v4l_print_pix_fmt (vfd, &p->fmt);
793 }
794 break;
795 }
796 case VIDIOC_S_FBUF:
797 {
798 struct v4l2_framebuffer *p=arg;
799 if (!vfd->vidioc_s_fbuf)
800 break;
801
802 dbgarg (cmd, "capability=%d, flags=%d, base=0x%08lx\n",
803 p->capability,p->flags,(unsigned long)p->base);
804 v4l_print_pix_fmt (vfd, &p->fmt);
805 ret=vfd->vidioc_s_fbuf(file, fh, arg);
806
807 break;
808 }
809 case VIDIOC_STREAMON:
810 {
811 enum v4l2_buf_type i = *(int *)arg;
812 if (!vfd->vidioc_streamon)
813 break;
814 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
815 ret=vfd->vidioc_streamon(file, fh,i);
816 break;
817 }
818 case VIDIOC_STREAMOFF:
819 {
820 enum v4l2_buf_type i = *(int *)arg;
821
822 if (!vfd->vidioc_streamoff)
823 break;
824 dbgarg (cmd, "type=%s\n", prt_names(i,v4l2_type_names_FIXME));
825 ret=vfd->vidioc_streamoff(file, fh, i);
826 break;
827 }
828 /* ---------- tv norms ---------- */
829 case VIDIOC_ENUMSTD:
830 {
831 struct v4l2_standard *p = arg;
832 unsigned int index = p->index;
833
834 if (!vfd->tvnormsize) {
835 printk (KERN_WARNING "%s: no TV norms defined!\n",
836 vfd->name);
837 break;
838 }
839
Sascha Hauer666c73d2006-09-13 13:26:11 -0300840 if (index<0 || index >= vfd->tvnormsize) {
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -0300841 ret=-EINVAL;
842 break;
843 }
844 v4l2_video_std_construct(p, vfd->tvnorms[p->index].id,
845 vfd->tvnorms[p->index].name);
846 p->index = index;
847
848 dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
849 "framelines=%d\n", p->index,
850 (unsigned long long)p->id, p->name,
851 p->frameperiod.numerator,
852 p->frameperiod.denominator,
853 p->framelines);
854
855 ret=0;
856 break;
857 }
858 case VIDIOC_G_STD:
859 {
860 v4l2_std_id *id = arg;
861
862 *id = vfd->current_norm;
863
864 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
865
866 ret=0;
867 break;
868 }
869 case VIDIOC_S_STD:
870 {
871 v4l2_std_id *id = arg;
872 unsigned int i;
873
874 if (!vfd->tvnormsize) {
875 printk (KERN_WARNING "%s: no TV norms defined!\n",
876 vfd->name);
877 break;
878 }
879
880 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
881
882 /* First search for exact match */
883 for (i = 0; i < vfd->tvnormsize; i++)
884 if (*id == vfd->tvnorms[i].id)
885 break;
886 /* Then for a generic video std that contains desired std */
887 if (i == vfd->tvnormsize)
888 for (i = 0; i < vfd->tvnormsize; i++)
889 if (*id & vfd->tvnorms[i].id)
890 break;
891 if (i == vfd->tvnormsize) {
892 break;
893 }
894
895 /* Calls the specific handler */
896 if (vfd->vidioc_s_std)
897 ret=vfd->vidioc_s_std(file, fh, i);
898 else
899 ret=-EINVAL;
900
901 /* Updates standard information */
902 if (!ret)
903 vfd->current_norm=*id;
904
905 break;
906 }
907 case VIDIOC_QUERYSTD:
908 {
909 v4l2_std_id *p=arg;
910
911 if (!vfd->vidioc_querystd)
912 break;
913 ret=vfd->vidioc_querystd(file, fh, arg);
914 if (!ret)
915 dbgarg (cmd, "detected std=%Lu\n",
916 (unsigned long long)*p);
917 break;
918 }
919 /* ------ input switching ---------- */
920 /* FIXME: Inputs can be handled inside videodev2 */
921 case VIDIOC_ENUMINPUT:
922 {
923 struct v4l2_input *p=arg;
924 int i=p->index;
925
926 if (!vfd->vidioc_enum_input)
927 break;
928 memset(p, 0, sizeof(*p));
929 p->index=i;
930
931 ret=vfd->vidioc_enum_input(file, fh, p);
932 if (!ret)
933 dbgarg (cmd, "index=%d, name=%s, type=%d, "
934 "audioset=%d, "
935 "tuner=%d, std=%Ld, status=%d\n",
936 p->index,p->name,p->type,p->audioset,
937 p->tuner,
938 (unsigned long long)p->std,
939 p->status);
940 break;
941 }
942 case VIDIOC_G_INPUT:
943 {
944 unsigned int *i = arg;
945
946 if (!vfd->vidioc_g_input)
947 break;
948 ret=vfd->vidioc_g_input(file, fh, i);
949 if (!ret)
950 dbgarg (cmd, "value=%d\n",*i);
951 break;
952 }
953 case VIDIOC_S_INPUT:
954 {
955 unsigned int *i = arg;
956
957 if (!vfd->vidioc_s_input)
958 break;
959 dbgarg (cmd, "value=%d\n",*i);
960 ret=vfd->vidioc_s_input(file, fh, *i);
961 break;
962 }
963
964 /* ------ output switching ---------- */
965 case VIDIOC_G_OUTPUT:
966 {
967 unsigned int *i = arg;
968
969 if (!vfd->vidioc_g_output)
970 break;
971 ret=vfd->vidioc_g_output(file, fh, i);
972 if (!ret)
973 dbgarg (cmd, "value=%d\n",*i);
974 break;
975 }
976 case VIDIOC_S_OUTPUT:
977 {
978 unsigned int *i = arg;
979
980 if (!vfd->vidioc_s_output)
981 break;
982 dbgarg (cmd, "value=%d\n",*i);
983 ret=vfd->vidioc_s_output(file, fh, *i);
984 break;
985 }
986
987 /* --- controls ---------------------------------------------- */
988 case VIDIOC_QUERYCTRL:
989 {
990 struct v4l2_queryctrl *p=arg;
991
992 if (!vfd->vidioc_queryctrl)
993 break;
994 ret=vfd->vidioc_queryctrl(file, fh, p);
995
996 if (!ret)
997 dbgarg (cmd, "id=%d, type=%d, name=%s, "
998 "min/max=%d/%d,"
999 " step=%d, default=%d, flags=0x%08x\n",
1000 p->id,p->type,p->name,p->minimum,
1001 p->maximum,p->step,p->default_value,
1002 p->flags);
1003 break;
1004 }
1005 case VIDIOC_G_CTRL:
1006 {
1007 struct v4l2_control *p = arg;
1008
1009 if (!vfd->vidioc_g_ctrl)
1010 break;
1011 dbgarg(cmd, "Enum for index=%d\n", p->id);
1012
1013 ret=vfd->vidioc_g_ctrl(file, fh, p);
1014 if (!ret)
1015 dbgarg2 ( "id=%d, value=%d\n", p->id, p->value);
1016 break;
1017 }
1018 case VIDIOC_S_CTRL:
1019 {
1020 struct v4l2_control *p = arg;
1021
1022 if (!vfd->vidioc_s_ctrl)
1023 break;
1024 dbgarg (cmd, "id=%d, value=%d\n", p->id, p->value);
1025
1026 ret=vfd->vidioc_s_ctrl(file, fh, p);
1027 break;
1028 }
Hans Verkuil05976912006-06-18 13:43:28 -03001029 case VIDIOC_G_EXT_CTRLS:
1030 {
1031 struct v4l2_ext_controls *p = arg;
1032
1033 if (vfd->vidioc_g_ext_ctrls) {
1034 dbgarg(cmd, "count=%d\n", p->count);
1035
1036 ret=vfd->vidioc_g_ext_ctrls(file, fh, p);
1037 }
1038 break;
1039 }
1040 case VIDIOC_S_EXT_CTRLS:
1041 {
1042 struct v4l2_ext_controls *p = arg;
1043
1044 if (vfd->vidioc_s_ext_ctrls) {
1045 dbgarg(cmd, "count=%d\n", p->count);
1046
1047 ret=vfd->vidioc_s_ext_ctrls(file, fh, p);
1048 }
1049 break;
1050 }
1051 case VIDIOC_TRY_EXT_CTRLS:
1052 {
1053 struct v4l2_ext_controls *p = arg;
1054
1055 if (vfd->vidioc_try_ext_ctrls) {
1056 dbgarg(cmd, "count=%d\n", p->count);
1057
1058 ret=vfd->vidioc_try_ext_ctrls(file, fh, p);
1059 }
1060 break;
1061 }
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001062 case VIDIOC_QUERYMENU:
1063 {
1064 struct v4l2_querymenu *p=arg;
1065 if (!vfd->vidioc_querymenu)
1066 break;
1067 ret=vfd->vidioc_querymenu(file, fh, p);
1068 if (!ret)
1069 dbgarg (cmd, "id=%d, index=%d, name=%s\n",
1070 p->id,p->index,p->name);
1071 break;
1072 }
1073 /* --- audio ---------------------------------------------- */
1074 case VIDIOC_ENUMAUDIO:
1075 {
1076 struct v4l2_audio *p=arg;
1077
1078 if (!vfd->vidioc_enumaudio)
1079 break;
1080 dbgarg(cmd, "Enum for index=%d\n", p->index);
1081 ret=vfd->vidioc_enumaudio(file, fh, p);
1082 if (!ret)
1083 dbgarg2("index=%d, name=%s, capability=%d, "
1084 "mode=%d\n",p->index,p->name,
1085 p->capability, p->mode);
1086 break;
1087 }
1088 case VIDIOC_G_AUDIO:
1089 {
1090 struct v4l2_audio *p=arg;
Mauro Carvalho Chehab7964b1b2006-11-20 12:10:43 -03001091 __u32 index=p->index;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001092
1093 if (!vfd->vidioc_g_audio)
1094 break;
Mauro Carvalho Chehab7964b1b2006-11-20 12:10:43 -03001095
1096 memset(p,0,sizeof(*p));
1097 p->index=index;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001098 dbgarg(cmd, "Get for index=%d\n", p->index);
1099 ret=vfd->vidioc_g_audio(file, fh, p);
1100 if (!ret)
1101 dbgarg2("index=%d, name=%s, capability=%d, "
1102 "mode=%d\n",p->index,
1103 p->name,p->capability, p->mode);
1104 break;
1105 }
1106 case VIDIOC_S_AUDIO:
1107 {
1108 struct v4l2_audio *p=arg;
1109
1110 if (!vfd->vidioc_s_audio)
1111 break;
1112 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1113 "mode=%d\n", p->index, p->name,
1114 p->capability, p->mode);
1115 ret=vfd->vidioc_s_audio(file, fh, p);
1116 break;
1117 }
1118 case VIDIOC_ENUMAUDOUT:
1119 {
1120 struct v4l2_audioout *p=arg;
1121
1122 if (!vfd->vidioc_enumaudout)
1123 break;
1124 dbgarg(cmd, "Enum for index=%d\n", p->index);
1125 ret=vfd->vidioc_enumaudout(file, fh, p);
1126 if (!ret)
1127 dbgarg2("index=%d, name=%s, capability=%d, "
1128 "mode=%d\n", p->index, p->name,
1129 p->capability,p->mode);
1130 break;
1131 }
1132 case VIDIOC_G_AUDOUT:
1133 {
1134 struct v4l2_audioout *p=arg;
1135
1136 if (!vfd->vidioc_g_audout)
1137 break;
1138 dbgarg(cmd, "Enum for index=%d\n", p->index);
1139 ret=vfd->vidioc_g_audout(file, fh, p);
1140 if (!ret)
1141 dbgarg2("index=%d, name=%s, capability=%d, "
1142 "mode=%d\n", p->index, p->name,
1143 p->capability,p->mode);
1144 break;
1145 }
1146 case VIDIOC_S_AUDOUT:
1147 {
1148 struct v4l2_audioout *p=arg;
1149
1150 if (!vfd->vidioc_s_audout)
1151 break;
1152 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1153 "mode=%d\n", p->index, p->name,
1154 p->capability,p->mode);
1155
1156 ret=vfd->vidioc_s_audout(file, fh, p);
1157 break;
1158 }
1159 case VIDIOC_G_MODULATOR:
1160 {
1161 struct v4l2_modulator *p=arg;
1162 if (!vfd->vidioc_g_modulator)
1163 break;
1164 ret=vfd->vidioc_g_modulator(file, fh, p);
1165 if (!ret)
1166 dbgarg(cmd, "index=%d, name=%s, "
1167 "capability=%d, rangelow=%d,"
1168 " rangehigh=%d, txsubchans=%d\n",
1169 p->index, p->name,p->capability,
1170 p->rangelow, p->rangehigh,
1171 p->txsubchans);
1172 break;
1173 }
1174 case VIDIOC_S_MODULATOR:
1175 {
1176 struct v4l2_modulator *p=arg;
1177 if (!vfd->vidioc_s_modulator)
1178 break;
1179 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1180 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1181 p->index, p->name,p->capability,p->rangelow,
1182 p->rangehigh,p->txsubchans);
1183 ret=vfd->vidioc_s_modulator(file, fh, p);
1184 break;
1185 }
1186 case VIDIOC_G_CROP:
1187 {
1188 struct v4l2_crop *p=arg;
1189 if (!vfd->vidioc_g_crop)
1190 break;
1191 ret=vfd->vidioc_g_crop(file, fh, p);
1192 if (!ret) {
1193 dbgarg(cmd, "type=%d\n", p->type);
1194 dbgrect(vfd, "", &p->c);
1195 }
1196 break;
1197 }
1198 case VIDIOC_S_CROP:
1199 {
1200 struct v4l2_crop *p=arg;
1201 if (!vfd->vidioc_s_crop)
1202 break;
1203 dbgarg(cmd, "type=%d\n", p->type);
1204 dbgrect(vfd, "", &p->c);
1205 ret=vfd->vidioc_s_crop(file, fh, p);
1206 break;
1207 }
1208 case VIDIOC_CROPCAP:
1209 {
1210 struct v4l2_cropcap *p=arg;
1211 /*FIXME: Should also show v4l2_fract pixelaspect */
1212 if (!vfd->vidioc_cropcap)
1213 break;
1214 dbgarg(cmd, "type=%d\n", p->type);
1215 dbgrect(vfd, "bounds ", &p->bounds);
1216 dbgrect(vfd, "defrect ", &p->defrect);
1217 ret=vfd->vidioc_cropcap(file, fh, p);
1218 break;
1219 }
1220 case VIDIOC_G_MPEGCOMP:
1221 {
1222 struct v4l2_mpeg_compression *p=arg;
Hans Verkuilf81cf752006-06-18 16:54:20 -03001223
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001224 /*FIXME: Several fields not shown */
1225 if (!vfd->vidioc_g_mpegcomp)
1226 break;
1227 ret=vfd->vidioc_g_mpegcomp(file, fh, p);
1228 if (!ret)
1229 dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d,"
1230 " ts_pid_video=%d, ts_pid_pcr=%d, "
1231 "ps_size=%d, au_sample_rate=%d, "
1232 "au_pesid=%c, vi_frame_rate=%d, "
1233 "vi_frames_per_gop=%d, "
1234 "vi_bframes_count=%d, vi_pesid=%c\n",
1235 p->ts_pid_pmt,p->ts_pid_audio,
1236 p->ts_pid_video,p->ts_pid_pcr,
1237 p->ps_size, p->au_sample_rate,
1238 p->au_pesid, p->vi_frame_rate,
1239 p->vi_frames_per_gop,
1240 p->vi_bframes_count, p->vi_pesid);
1241 break;
1242 }
1243 case VIDIOC_S_MPEGCOMP:
1244 {
1245 struct v4l2_mpeg_compression *p=arg;
1246 /*FIXME: Several fields not shown */
1247 if (!vfd->vidioc_s_mpegcomp)
1248 break;
1249 dbgarg (cmd, "ts_pid_pmt=%d, ts_pid_audio=%d, "
1250 "ts_pid_video=%d, ts_pid_pcr=%d, ps_size=%d, "
1251 "au_sample_rate=%d, au_pesid=%c, "
1252 "vi_frame_rate=%d, vi_frames_per_gop=%d, "
1253 "vi_bframes_count=%d, vi_pesid=%c\n",
1254 p->ts_pid_pmt,p->ts_pid_audio, p->ts_pid_video,
1255 p->ts_pid_pcr, p->ps_size, p->au_sample_rate,
1256 p->au_pesid, p->vi_frame_rate,
1257 p->vi_frames_per_gop, p->vi_bframes_count,
1258 p->vi_pesid);
1259 ret=vfd->vidioc_s_mpegcomp(file, fh, p);
1260 break;
1261 }
1262 case VIDIOC_G_JPEGCOMP:
1263 {
1264 struct v4l2_jpegcompression *p=arg;
1265 if (!vfd->vidioc_g_jpegcomp)
1266 break;
1267 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1268 if (!ret)
1269 dbgarg (cmd, "quality=%d, APPn=%d, "
1270 "APP_len=%d, COM_len=%d, "
1271 "jpeg_markers=%d\n",
1272 p->quality,p->APPn,p->APP_len,
1273 p->COM_len,p->jpeg_markers);
1274 break;
1275 }
1276 case VIDIOC_S_JPEGCOMP:
1277 {
1278 struct v4l2_jpegcompression *p=arg;
1279 if (!vfd->vidioc_g_jpegcomp)
1280 break;
1281 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1282 "COM_len=%d, jpeg_markers=%d\n",
1283 p->quality,p->APPn,p->APP_len,
1284 p->COM_len,p->jpeg_markers);
1285 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1286 break;
1287 }
1288 case VIDIOC_G_PARM:
1289 {
1290 struct v4l2_streamparm *p=arg;
Mauro Carvalho Chehab1c2d0342006-09-14 13:36:34 -03001291 if (vfd->vidioc_g_parm) {
1292 ret=vfd->vidioc_g_parm(file, fh, p);
1293 } else {
1294 struct v4l2_standard s;
Jonathan Corbet83427ac2006-10-13 07:51:16 -03001295 int i;
Mauro Carvalho Chehab1c2d0342006-09-14 13:36:34 -03001296
1297 if (!vfd->tvnormsize) {
1298 printk (KERN_WARNING "%s: no TV norms defined!\n",
1299 vfd->name);
1300 break;
1301 }
1302
1303 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1304 return -EINVAL;
1305
Jonathan Corbet83427ac2006-10-13 07:51:16 -03001306 for (i = 0; i < vfd->tvnormsize; i++)
1307 if (vfd->tvnorms[i].id == vfd->current_norm)
1308 break;
1309 if (i >= vfd->tvnormsize)
1310 return -EINVAL;
1311
1312 v4l2_video_std_construct(&s, vfd->current_norm,
1313 vfd->tvnorms[i].name);
Mauro Carvalho Chehab1c2d0342006-09-14 13:36:34 -03001314
1315 memset(p,0,sizeof(*p));
1316
1317 p->parm.capture.timeperframe = s.frameperiod;
1318 ret=0;
1319 }
1320
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001321 dbgarg (cmd, "type=%d\n", p->type);
1322 break;
1323 }
1324 case VIDIOC_S_PARM:
1325 {
1326 struct v4l2_streamparm *p=arg;
1327 if (!vfd->vidioc_s_parm)
1328 break;
1329 dbgarg (cmd, "type=%d\n", p->type);
1330 ret=vfd->vidioc_s_parm(file, fh, p);
1331 break;
1332 }
1333 case VIDIOC_G_TUNER:
1334 {
1335 struct v4l2_tuner *p=arg;
Mauro Carvalho Chehab7964b1b2006-11-20 12:10:43 -03001336 __u32 index=p->index;
1337
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001338 if (!vfd->vidioc_g_tuner)
1339 break;
Mauro Carvalho Chehab7964b1b2006-11-20 12:10:43 -03001340
1341 memset(p,0,sizeof(*p));
1342 p->index=index;
1343
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001344 ret=vfd->vidioc_g_tuner(file, fh, p);
1345 if (!ret)
1346 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1347 "capability=%d, rangelow=%d, "
1348 "rangehigh=%d, signal=%d, afc=%d, "
1349 "rxsubchans=%d, audmode=%d\n",
1350 p->index, p->name, p->type,
1351 p->capability, p->rangelow,
1352 p->rangehigh, p->rxsubchans,
1353 p->audmode, p->signal, p->afc);
1354 break;
1355 }
1356 case VIDIOC_S_TUNER:
1357 {
1358 struct v4l2_tuner *p=arg;
1359 if (!vfd->vidioc_s_tuner)
1360 break;
1361 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1362 "capability=%d, rangelow=%d, rangehigh=%d, "
1363 "signal=%d, afc=%d, rxsubchans=%d, "
1364 "audmode=%d\n",p->index, p->name, p->type,
1365 p->capability, p->rangelow,p->rangehigh,
1366 p->rxsubchans, p->audmode, p->signal,
1367 p->afc);
1368 ret=vfd->vidioc_s_tuner(file, fh, p);
1369 break;
1370 }
1371 case VIDIOC_G_FREQUENCY:
1372 {
1373 struct v4l2_frequency *p=arg;
1374 if (!vfd->vidioc_g_frequency)
1375 break;
Mauro Carvalho Chehab7964b1b2006-11-20 12:10:43 -03001376
1377 memset(p,0,sizeof(*p));
1378
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001379 ret=vfd->vidioc_g_frequency(file, fh, p);
1380 if (!ret)
1381 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1382 p->tuner,p->type,p->frequency);
1383 break;
1384 }
1385 case VIDIOC_S_FREQUENCY:
1386 {
1387 struct v4l2_frequency *p=arg;
1388 if (!vfd->vidioc_s_frequency)
1389 break;
1390 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1391 p->tuner,p->type,p->frequency);
1392 ret=vfd->vidioc_s_frequency(file, fh, p);
1393 break;
1394 }
1395 case VIDIOC_G_SLICED_VBI_CAP:
1396 {
1397 struct v4l2_sliced_vbi_cap *p=arg;
1398 if (!vfd->vidioc_g_sliced_vbi_cap)
1399 break;
1400 ret=vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1401 if (!ret)
1402 dbgarg (cmd, "service_set=%d\n", p->service_set);
1403 break;
1404 }
1405 case VIDIOC_LOG_STATUS:
1406 {
1407 if (!vfd->vidioc_log_status)
1408 break;
1409 ret=vfd->vidioc_log_status(file, fh);
1410 break;
1411 }
1412
1413 /* --- Others --------------------------------------------- */
1414
1415 default:
1416 ret=v4l_compat_translate_ioctl(inode,file,cmd,arg,__video_do_ioctl);
1417 }
1418
1419 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1420 if (ret<0) {
1421 printk ("%s: err:\n", vfd->name);
1422 v4l_print_ioctl(vfd->name, cmd);
1423 }
1424 }
1425
1426 return ret;
1427}
1428
1429int video_ioctl2 (struct inode *inode, struct file *file,
1430 unsigned int cmd, unsigned long arg)
1431{
1432 char sbuf[128];
1433 void *mbuf = NULL;
1434 void *parg = NULL;
1435 int err = -EINVAL;
Hans Verkuil05976912006-06-18 13:43:28 -03001436 int is_ext_ctrl;
1437 size_t ctrls_size = 0;
1438 void __user *user_ptr = NULL;
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001439
1440#ifdef __OLD_VIDIOC_
1441 cmd = video_fix_command(cmd);
1442#endif
Hans Verkuil05976912006-06-18 13:43:28 -03001443 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1444 cmd == VIDIOC_TRY_EXT_CTRLS);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001445
1446 /* Copy arguments into temp kernel buffer */
1447 switch (_IOC_DIR(cmd)) {
1448 case _IOC_NONE:
1449 parg = NULL;
1450 break;
1451 case _IOC_READ:
1452 case _IOC_WRITE:
1453 case (_IOC_WRITE | _IOC_READ):
1454 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1455 parg = sbuf;
1456 } else {
1457 /* too big to allocate from stack */
1458 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1459 if (NULL == mbuf)
1460 return -ENOMEM;
1461 parg = mbuf;
1462 }
1463
1464 err = -EFAULT;
1465 if (_IOC_DIR(cmd) & _IOC_WRITE)
1466 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1467 goto out;
1468 break;
1469 }
1470
Hans Verkuil05976912006-06-18 13:43:28 -03001471 if (is_ext_ctrl) {
1472 struct v4l2_ext_controls *p = parg;
1473
1474 /* In case of an error, tell the caller that it wasn't
1475 a specific control that caused it. */
1476 p->error_idx = p->count;
1477 user_ptr = (void __user *)p->controls;
1478 if (p->count) {
1479 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1480 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1481 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1482 err = -ENOMEM;
1483 if (NULL == mbuf)
1484 goto out_ext_ctrl;
1485 err = -EFAULT;
1486 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1487 goto out_ext_ctrl;
1488 p->controls = mbuf;
1489 }
1490 }
1491
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001492 /* Handles IOCTL */
1493 err = __video_do_ioctl(inode, file, cmd, parg);
1494 if (err == -ENOIOCTLCMD)
1495 err = -EINVAL;
Hans Verkuil05976912006-06-18 13:43:28 -03001496 if (is_ext_ctrl) {
1497 struct v4l2_ext_controls *p = parg;
1498
1499 p->controls = (void *)user_ptr;
1500 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1501 err = -EFAULT;
1502 goto out_ext_ctrl;
1503 }
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001504 if (err < 0)
1505 goto out;
1506
Hans Verkuil05976912006-06-18 13:43:28 -03001507out_ext_ctrl:
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001508 /* Copy results into user buffer */
1509 switch (_IOC_DIR(cmd))
1510 {
1511 case _IOC_READ:
1512 case (_IOC_WRITE | _IOC_READ):
1513 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1514 err = -EFAULT;
1515 break;
1516 }
1517
1518out:
1519 kfree(mbuf);
1520 return err;
1521}
1522
1523
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524static struct file_operations video_fops;
1525
1526/**
1527 * video_register_device - register video4linux devices
1528 * @vfd: video device structure we want to register
1529 * @type: type of device to register
1530 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
1531 * -1 == first free)
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -08001532 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 * The registration code assigns minor numbers based on the type
1534 * requested. -ENFILE is returned in all the device slots for this
1535 * category are full. If not then the minor field is set and the
1536 * driver initialize function is called (if non %NULL).
1537 *
1538 * Zero is returned on success.
1539 *
1540 * Valid types are
1541 *
1542 * %VFL_TYPE_GRABBER - A frame grabber
1543 *
1544 * %VFL_TYPE_VTX - A teletext device
1545 *
1546 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
1547 *
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -08001548 * %VFL_TYPE_RADIO - A radio card
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 */
1550
1551int video_register_device(struct video_device *vfd, int type, int nr)
1552{
1553 int i=0;
1554 int base;
1555 int end;
Michael Krufky3117bee2006-07-19 13:23:38 -03001556 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 char *name_base;
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -08001558
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 switch(type)
1560 {
1561 case VFL_TYPE_GRABBER:
Mauro Carvalho Chehab4d0dddb2006-01-23 17:11:07 -02001562 base=MINOR_VFL_TYPE_GRABBER_MIN;
1563 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 name_base = "video";
1565 break;
1566 case VFL_TYPE_VTX:
Mauro Carvalho Chehab4d0dddb2006-01-23 17:11:07 -02001567 base=MINOR_VFL_TYPE_VTX_MIN;
1568 end=MINOR_VFL_TYPE_VTX_MAX+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 name_base = "vtx";
1570 break;
1571 case VFL_TYPE_VBI:
Mauro Carvalho Chehab4d0dddb2006-01-23 17:11:07 -02001572 base=MINOR_VFL_TYPE_VBI_MIN;
1573 end=MINOR_VFL_TYPE_VBI_MAX+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 name_base = "vbi";
1575 break;
1576 case VFL_TYPE_RADIO:
Mauro Carvalho Chehab4d0dddb2006-01-23 17:11:07 -02001577 base=MINOR_VFL_TYPE_RADIO_MIN;
1578 end=MINOR_VFL_TYPE_RADIO_MAX+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 name_base = "radio";
1580 break;
1581 default:
Trent Piepho53dd8de2006-07-25 09:31:42 -03001582 printk(KERN_ERR "%s called with unknown type: %d\n",
1583 __FUNCTION__, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 return -1;
1585 }
1586
1587 /* pick a minor number */
Ingo Molnar1e4baed2006-01-15 07:52:23 -02001588 mutex_lock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 if (nr >= 0 && nr < end-base) {
1590 /* use the one the driver asked for */
1591 i = base+nr;
1592 if (NULL != video_device[i]) {
Ingo Molnar1e4baed2006-01-15 07:52:23 -02001593 mutex_unlock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 return -ENFILE;
1595 }
1596 } else {
1597 /* use first free */
1598 for(i=base;i<end;i++)
1599 if (NULL == video_device[i])
1600 break;
1601 if (i == end) {
Ingo Molnar1e4baed2006-01-15 07:52:23 -02001602 mutex_unlock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 return -ENFILE;
1604 }
1605 }
1606 video_device[i]=vfd;
1607 vfd->minor=i;
Ingo Molnar1e4baed2006-01-15 07:52:23 -02001608 mutex_unlock(&videodev_lock);
Ingo Molnar3593cab2006-02-07 06:49:14 -02001609 mutex_init(&vfd->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
1611 /* sysfs class */
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -08001612 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 if (vfd->dev)
1614 vfd->class_dev.dev = vfd->dev;
1615 vfd->class_dev.class = &video_class;
Michael Krufky50c25ff2006-01-09 15:25:34 -02001616 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
Greg Kroah-Hartman5e483072005-06-20 21:15:16 -07001617 sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base);
Michael Krufky3117bee2006-07-19 13:23:38 -03001618 ret = class_device_register(&vfd->class_dev);
Trent Piepho8c313112006-07-25 20:37:03 -03001619 if (ret < 0) {
Michael Krufky3117bee2006-07-19 13:23:38 -03001620 printk(KERN_ERR "%s: class_device_register failed\n",
1621 __FUNCTION__);
Trent Piephod94fc9a2006-07-29 17:18:06 -03001622 goto fail_minor;
Michael Krufky3117bee2006-07-19 13:23:38 -03001623 }
Mauro Carvalho Chehab985bc962006-07-23 06:31:19 -03001624 ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
1625 if (ret < 0) {
Trent Piephod94fc9a2006-07-29 17:18:06 -03001626 printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
1627 __FUNCTION__);
1628 goto fail_classdev;
Mauro Carvalho Chehab985bc962006-07-23 06:31:19 -03001629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Mauro Carvalho Chehabd21838d2006-01-09 15:25:21 -02001631#if 1
1632 /* needed until all drivers are fixed */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 if (!vfd->release)
1634 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
1635 "Please fix your driver for proper sysfs support, see "
1636 "http://lwn.net/Articles/36850/\n", vfd->name);
1637#endif
1638 return 0;
Trent Piepho53dd8de2006-07-25 09:31:42 -03001639
1640fail_classdev:
1641 class_device_unregister(&vfd->class_dev);
1642fail_minor:
1643 mutex_lock(&videodev_lock);
1644 video_device[vfd->minor] = NULL;
1645 vfd->minor = -1;
1646 mutex_unlock(&videodev_lock);
1647 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648}
1649
1650/**
1651 * video_unregister_device - unregister a video4linux device
1652 * @vfd: the device to unregister
1653 *
1654 * This unregisters the passed device and deassigns the minor
1655 * number. Future open calls will be met with errors.
1656 */
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -08001657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658void video_unregister_device(struct video_device *vfd)
1659{
Ingo Molnar1e4baed2006-01-15 07:52:23 -02001660 mutex_lock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 if(video_device[vfd->minor]!=vfd)
1662 panic("videodev: bad unregister");
1663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 video_device[vfd->minor]=NULL;
1665 class_device_unregister(&vfd->class_dev);
Ingo Molnar1e4baed2006-01-15 07:52:23 -02001666 mutex_unlock(&videodev_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667}
1668
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001669/*
1670 * Video fs operations
1671 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672static struct file_operations video_fops=
1673{
1674 .owner = THIS_MODULE,
1675 .llseek = no_llseek,
1676 .open = video_open,
1677};
1678
1679/*
1680 * Initialise video for linux
1681 */
Sigmund Augdal Helberg938606b2005-12-01 00:51:19 -08001682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683static int __init videodev_init(void)
1684{
1685 int ret;
1686
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001687 printk(KERN_INFO "Linux video capture interface: v2.00\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
1689 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
1690 return -EIO;
1691 }
1692
1693 ret = class_register(&video_class);
1694 if (ret < 0) {
1695 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
1696 printk(KERN_WARNING "video_dev: class_register failed\n");
1697 return -EIO;
1698 }
1699
1700 return 0;
1701}
1702
1703static void __exit videodev_exit(void)
1704{
1705 class_unregister(&video_class);
1706 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
1707}
1708
1709module_init(videodev_init)
1710module_exit(videodev_exit)
1711
1712EXPORT_SYMBOL(video_register_device);
1713EXPORT_SYMBOL(video_unregister_device);
1714EXPORT_SYMBOL(video_devdata);
1715EXPORT_SYMBOL(video_usercopy);
1716EXPORT_SYMBOL(video_exclusive_open);
1717EXPORT_SYMBOL(video_exclusive_release);
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001718EXPORT_SYMBOL(video_ioctl2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719EXPORT_SYMBOL(video_device_alloc);
1720EXPORT_SYMBOL(video_device_release);
1721
Mauro Carvalho Chehab401998f2006-06-04 10:06:18 -03001722MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
1723MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724MODULE_LICENSE("GPL");
1725
1726
1727/*
1728 * Local variables:
1729 * c-basic-offset: 8
1730 * End:
1731 */