2 * Video capture interface for Linux
4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
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.
12 * Author: Alan Cox, <alan@redhat.com>
17 #include <linux/config.h>
18 #include <linux/version.h>
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/sched.h>
24 #include <linux/string.h>
25 #include <linux/errno.h>
26 #include <linux/videodev.h>
28 #if LINUX_VERSION_CODE >= 0x020100
29 #include <asm/uaccess.h>
31 #include <asm/system.h>
33 #include <linux/kmod.h>
36 #define VIDEO_NUM_DEVICES 256
42 static struct video_device
*video_device
[VIDEO_NUM_DEVICES
];
44 #ifdef CONFIG_VIDEO_BT848
45 extern int init_bttv_cards(struct video_init
*);
46 extern int i2c_tuner_init(struct video_init
*);
48 #ifdef CONFIG_VIDEO_SAA5249
49 extern int init_saa_5249(struct video_init
*);
51 #ifdef CONFIG_VIDEO_CQCAM
52 extern int init_colour_qcams(struct video_init
*);
54 #ifdef CONFIG_VIDEO_BWQCAM
55 extern int init_bw_qcams(struct video_init
*);
57 #ifdef CONFIG_VIDEO_PLANB
58 extern int init_planbs(struct video_init
*);
60 #ifdef CONFIG_RADIO_RTRACK2
61 extern int rtrack2_init(struct video_init
*);
63 #ifdef CONFIG_RADIO_SF16FMI
64 extern int fmi_init(struct video_init
*);
66 #ifdef CONFIG_RADIO_TYPHOON
67 extern int typhoon_init(struct video_init
*);
69 #ifdef CONFIG_RADIO_CADET
70 extern int cadet_init(struct video_init
*);
72 #ifdef CONFIG_RADIO_TERRATEC
73 extern int terratec_init(struct video_init
*);
75 #ifdef CONFIG_VIDEO_ZORAN
76 extern int init_zoran_cards(struct video_init
*);
79 static struct video_init video_init_list
[]={
80 #ifdef CONFIG_VIDEO_BT848
81 {"i2c-tuner", i2c_tuner_init
},
82 {"bttv", init_bttv_cards
},
84 #ifdef CONFIG_VIDEO_SAA5249
85 {"saa5249", init_saa_5249
},
87 #ifdef CONFIG_VIDEO_CQCAM
88 {"c-qcam", init_colour_qcams
},
90 #ifdef CONFIG_VIDEO_BWQCAM
91 {"bw-qcam", init_bw_qcams
},
93 #ifdef CONFIG_VIDEO_PLANB
94 {"planb", init_planbs
},
96 #ifdef CONFIG_RADIO_RTRACK2
97 {"RTrack2", rtrack2_init
},
99 #ifdef CONFIG_RADIO_SF16FMI
100 {"SF16FMI", fmi_init
},
102 #ifdef CONFIG_RADIO_CADET
103 {"Cadet", cadet_init
},
105 #ifdef CONFIG_RADIO_TYPHOON
106 {"radio-typhoon", typhoon_init
},
108 #ifdef CONFIG_RADIO_TERRATEC
109 {"radio-terratec", terratec_init
},
111 #ifdef CONFIG_VIDEO_ZORAN
112 {"zoran", init_zoran_cards
},
118 * Read will do some smarts later on. Buffer pin etc.
121 static ssize_t
video_read(struct file
*file
,
122 char *buf
, size_t count
, loff_t
*ppos
)
124 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
126 return vfl
->read(vfl
, buf
, count
, file
->f_flags
&O_NONBLOCK
);
133 * Write for now does nothing. No reason it shouldnt do overlay setting
134 * for some boards I guess..
137 static ssize_t
video_write(struct file
*file
, const char *buf
,
138 size_t count
, loff_t
*ppos
)
140 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
142 return vfl
->write(vfl
, buf
, count
, file
->f_flags
&O_NONBLOCK
);
148 * Poll to see if we're readable, can probably be used for timing on incoming
152 static unsigned int video_poll(struct file
*file
, poll_table
* wait
)
154 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
156 return vfl
->poll(vfl
, file
, wait
);
163 * Open a video device.
166 static int video_open(struct inode
*inode
, struct file
*file
)
168 unsigned int minor
= MINOR(inode
->i_rdev
);
170 struct video_device
*vfl
;
172 if(minor
>=VIDEO_NUM_DEVICES
)
175 vfl
=video_device
[minor
];
179 sprintf (modname
, "char-major-%d-%d", VIDEO_MAJOR
, minor
);
180 request_module(modname
);
181 vfl
=video_device
[minor
];
187 vfl
->busy
=1; /* In case vfl->open sleeps */
191 err
=vfl
->open(vfl
,0); /* Tell the device it is open */
202 * Last close of a video for Linux device
205 static int video_release(struct inode
*inode
, struct file
*file
)
207 struct video_device
*vfl
=video_device
[MINOR(inode
->i_rdev
)];
215 * Question: Should we be able to capture and then seek around the
219 #if LINUX_VERSION_CODE >= 0x020100
220 static long long video_lseek(struct file
* file
,
221 long long offset
, int origin
)
226 static long long video_lseek(struct inode
*inode
, struct file
* file
,
227 long long offset
, int origin
)
234 static int video_ioctl(struct inode
*inode
, struct file
*file
,
235 unsigned int cmd
, unsigned long arg
)
237 struct video_device
*vfl
=video_device
[MINOR(inode
->i_rdev
)];
238 int err
=vfl
->ioctl(vfl
, cmd
, (void *)arg
);
240 if(err
!=-ENOIOCTLCMD
)
251 * We need to do MMAP support
255 #if LINUX_VERSION_CODE >= 0x020100
256 int video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
258 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
260 static int video_mmap(struct inode
* ino
, struct file
* file
,
261 struct vm_area_struct
* vma
)
263 struct video_device
*vfl
=video_device
[MINOR(ino
->i_rdev
)];
266 return vfl
->mmap(vfl
, (char *)vma
->vm_start
,
267 (unsigned long)(vma
->vm_end
-vma
->vm_start
));
272 * Video For Linux device drivers request registration here.
275 int video_register_device(struct video_device
*vfd
, int type
)
284 case VFL_TYPE_GRABBER
:
304 for(i
=base
;i
<end
;i
++)
306 if(video_device
[i
]==NULL
)
310 /* The init call may sleep so we book the slot out
315 err
=vfd
->initialize(vfd
);
318 video_device
[i
]=NULL
;
330 * Unregister an unused video for linux device
333 void video_unregister_device(struct video_device
*vfd
)
335 if(video_device
[vfd
->minor
]!=vfd
)
336 panic("vfd: bad unregister");
337 video_device
[vfd
->minor
]=NULL
;
342 static struct file_operations video_fops
=
348 #if LINUX_VERSION_CODE >= 0x020100
349 video_poll
, /* poll */
356 #if LINUX_VERSION_CODE >= 0x020100
363 * Initialise video for linux
366 int videodev_init(void)
368 struct video_init
*vfli
= video_init_list
;
370 printk(KERN_INFO
"Linux video capture interface: v1.00\n");
371 if(register_chrdev(VIDEO_MAJOR
,"video_capture", &video_fops
))
373 printk("video_dev: unable to get major %d\n", VIDEO_MAJOR
);
378 * Init kernel installed video drivers
381 while(vfli
->init
!=NULL
)
390 int init_module(void)
392 return videodev_init();
395 void cleanup_module(void)
397 unregister_chrdev(VIDEO_MAJOR
, "video_capture");
408 #if LINUX_VERSION_CODE >= 0x020100
409 EXPORT_SYMBOL(video_register_device
);
410 EXPORT_SYMBOL(video_unregister_device
);