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@cymru.net>
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
23 #include <linux/string.h>
24 #include <linux/errno.h>
25 #include <linux/videodev.h>
27 #include <asm/uaccess.h>
28 #include <asm/system.h>
31 #include <linux/kmod.h>
35 #define VIDEO_NUM_DEVICES 256
41 static struct video_device
*video_device
[VIDEO_NUM_DEVICES
];
43 #ifdef CONFIG_VIDEO_BT848
44 extern int init_bttv_cards(struct video_init
*);
45 extern int i2c_tuner_init(struct video_init
*);
47 #ifdef CONFIG_VIDEO_SAA5249
48 extern int init_saa_5249(struct video_init
*);
50 #ifdef CONFIG_VIDEO_CQCAM
51 extern int init_colour_qcams(struct video_init
*);
53 #ifdef CONFIG_VIDEO_BWQCAM
54 extern int init_bw_qcams(struct video_init
*);
56 #ifdef CONFIG_RADIO_AZTECH
57 extern int aztech_init(struct video_init
*);
59 #ifdef CONFIG_RADIO_RTRACK
60 extern int rtrack_init(struct video_init
*);
62 #ifdef CONFIG_RADIO_SF16FMI
63 extern int fmi_init(struct video_init
*);
65 #ifdef CONFIG_RADIO_MIROPCM20
66 extern int pcm20_init(struct video_init
*);
69 static struct video_init video_init_list
[]={
70 #ifdef CONFIG_VIDEO_BT848
71 {"i2c-tuner", i2c_tuner_init
},
72 {"bttv", init_bttv_cards
},
74 #ifdef CONFIG_VIDEO_SAA5249
75 {"saa5249", init_saa_5249
},
77 #ifdef CONFIG_VIDEO_CQCAM
78 {"c-qcam", init_colour_qcams
},
80 #ifdef CONFIG_VIDEO_BWQCAM
81 {"bw-qcam", init_bw_qcams
},
83 #ifdef CONFIG_VIDEO_PMS
84 {"PMS", init_pms_cards
},
86 #ifdef CONFIG_RADIO_AZTECH
87 {"Aztech", aztech_init
},
89 #ifdef CONFIG_RADIO_RTRACK
90 {"RTrack", rtrack_init
},
92 #ifdef CONFIG_RADIO_SF16FMI
93 {"SF16FMI", fmi_init
},
95 #ifdef CONFIG_RADIO_MIROPCM20
96 {"PCM20", pcm20_init
},
103 * Read will do some smarts later on. Buffer pin etc.
106 static ssize_t
video_read(struct file
*file
,
107 char *buf
, size_t count
, loff_t
*ppos
)
109 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
111 return vfl
->read(vfl
, buf
, count
, file
->f_flags
&O_NONBLOCK
);
118 * Write for now does nothing. No reason it shouldnt do overlay setting
119 * for some boards I guess..
122 static ssize_t
video_write(struct file
*file
, const char *buf
,
123 size_t count
, loff_t
*ppos
)
125 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
127 return vfl
->write(vfl
, buf
, count
, file
->f_flags
&O_NONBLOCK
);
134 * Poll to see if we're readable, can probably be used for timing on incoming
138 static unsigned int video_poll(struct file
*file
, poll_table
* wait
)
140 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
142 return vfl
->poll(vfl
, file
, wait
);
148 * Open a video device.
151 static int video_open(struct inode
*inode
, struct file
*file
)
153 unsigned int minor
= MINOR(inode
->i_rdev
);
155 struct video_device
*vfl
;
157 if(minor
>=VIDEO_NUM_DEVICES
)
160 vfl
=video_device
[minor
];
165 sprintf (modname
, "char-major-%d-%d", VIDEO_MAJOR
, minor
);
166 request_module(modname
);
167 vfl
=video_device
[minor
];
174 vfl
->busy
=1; /* In case vfl->open sleeps */
178 err
=vfl
->open(vfl
,0); /* Tell the device it is open */
189 * Last close of a video for Linux device
192 static int video_release(struct inode
*inode
, struct file
*file
)
194 struct video_device
*vfl
=video_device
[MINOR(inode
->i_rdev
)];
202 * Question: Should we be able to capture and then seek around the
206 static long long video_lseek(struct file
* file
,
207 long long offset
, int origin
)
213 static int video_ioctl(struct inode
*inode
, struct file
*file
,
214 unsigned int cmd
, unsigned long arg
)
216 struct video_device
*vfl
=video_device
[MINOR(inode
->i_rdev
)];
217 int err
=vfl
->ioctl(vfl
, cmd
, (void *)arg
);
219 if(err
!=-ENOIOCTLCMD
)
230 * We need to do MMAP support
234 int video_mmap(struct file
*file
, struct vm_area_struct
*vma
)
236 struct video_device
*vfl
=video_device
[MINOR(file
->f_dentry
->d_inode
->i_rdev
)];
238 return vfl
->mmap(vfl
, (char *)vma
->vm_start
,
239 (unsigned long)(vma
->vm_end
-vma
->vm_start
));
244 * Video For Linux device drivers request registration here.
247 int video_register_device(struct video_device
*vfd
, int type
)
256 case VFL_TYPE_GRABBER
:
276 for(i
=base
;i
<end
;i
++)
278 if(video_device
[i
]==NULL
)
282 /* The init call may sleep so we book the slot out
287 err
=vfd
->initialize(vfd
);
290 video_device
[i
]=NULL
;
302 * Unregister an unused video for linux device
305 void video_unregister_device(struct video_device
*vfd
)
307 if(video_device
[vfd
->minor
]!=vfd
)
308 panic("vfd: bad unregister");
309 video_device
[vfd
->minor
]=NULL
;
314 static struct file_operations video_fops
=
320 video_poll
, /* poll */
329 * Initialise video for linux
332 int videodev_init(void)
334 struct video_init
*vfli
= video_init_list
;
336 printk(KERN_INFO
"Linux video capture interface: v0.01 ALPHA\n");
337 if(register_chrdev(VIDEO_MAJOR
,"video_capture", &video_fops
))
339 printk("video_dev: unable to get major %d\n", VIDEO_MAJOR
);
344 * Init kernel installed video drivers
347 while(vfli
->init
!=NULL
)
356 int init_module(void)
358 return videodev_init();
361 void cleanup_module(void)
363 unregister_chrdev(VIDEO_MAJOR
, "video_capture");
368 EXPORT_SYMBOL(video_register_device
);
369 EXPORT_SYMBOL(video_unregister_device
);