19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/errno.h>
27 #include <linux/slab.h>
28 #include <asm/uaccess.h>
34 #define VIDEO_NUM_DEVICES 256
35 #define VIDEO_NAME "video4linux"
58 const char *
buf,
size_t len)
99 #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
101 static inline unsigned long *devnode_bits(
int vfl_type)
108 return devnode_nums[
idx];
112 static inline unsigned long *devnode_bits(
int vfl_type)
119 static inline void devnode_set(
struct video_device *vdev)
125 static inline void devnode_clear(
struct video_device *vdev)
131 static inline int devnode_find(
struct video_device *vdev,
int from,
int to)
138 return kzalloc(
sizeof(
struct video_device),
GFP_KERNEL);
155 static inline void video_get(
struct video_device *vdev)
160 static inline void video_put(
struct video_device *vdev)
166 static void v4l2_device_release(
struct device *cd)
192 #if defined(CONFIG_MEDIA_CONTROLLER)
193 if (v4l2_dev && v4l2_dev->mdev &&
218 static struct class video_class = {
220 .dev_attrs = video_device_attrs,
225 return video_device[iminor(file->
f_path.dentry->d_inode)];
241 memset(global, 0,
sizeof(*global));
248 if (!prio_is_valid(
new))
254 if (prio_is_valid(*local))
269 if (prio_is_valid(local))
293 static ssize_t v4l2_read(
struct file *filp,
char __user *buf,
294 size_t sz, loff_t *off)
299 if (!vdev->
fops->read)
301 if (video_is_registered(vdev))
302 ret = vdev->
fops->read(filp, buf, sz, off);
305 video_device_node_name(vdev), sz, ret);
309 static ssize_t v4l2_write(
struct file *filp,
const char __user *buf,
310 size_t sz, loff_t *off)
315 if (!vdev->
fops->write)
317 if (video_is_registered(vdev))
318 ret = vdev->
fops->write(filp, buf, sz, off);
321 video_device_node_name(vdev), sz, ret);
330 if (!vdev->
fops->poll)
332 if (video_is_registered(vdev))
333 res = vdev->
fops->poll(filp, poll);
336 video_device_node_name(vdev), res);
340 static long v4l2_ioctl(
struct file *filp,
unsigned int cmd,
unsigned long arg)
345 if (vdev->
fops->unlocked_ioctl) {
350 if (video_is_registered(vdev))
351 ret = vdev->
fops->unlocked_ioctl(filp, cmd, arg);
354 }
else if (vdev->
fops->ioctl) {
379 &vdev->
v4l2_dev->ioctl_lock : &v4l2_ioctl_mutex;
383 if (video_is_registered(vdev))
384 ret = vdev->
fops->ioctl(filp, cmd, arg);
394 #define v4l2_get_unmapped_area NULL
396 static unsigned long v4l2_get_unmapped_area(
struct file *filp,
397 unsigned long addr,
unsigned long len,
unsigned long pgoff,
403 if (!vdev->
fops->get_unmapped_area)
405 if (!video_is_registered(vdev))
407 ret = vdev->
fops->get_unmapped_area(filp, addr, len, pgoff, flags);
410 video_device_node_name(vdev), ret);
420 if (!vdev->
fops->mmap)
422 if (video_is_registered(vdev))
423 ret = vdev->
fops->mmap(filp, vm);
426 video_device_node_name(vdev), ret);
433 struct video_device *vdev;
440 if (vdev ==
NULL || !video_is_registered(vdev)) {
447 if (vdev->
fops->open) {
448 if (video_is_registered(vdev))
449 ret = vdev->
fops->open(filp);
456 video_device_node_name(vdev), ret);
464 static int v4l2_release(
struct inode *inode,
struct file *filp)
469 if (vdev->
fops->release)
470 ret = vdev->
fops->release(filp);
473 video_device_node_name(vdev));
486 .get_unmapped_area = v4l2_get_unmapped_area,
488 .unlocked_ioctl = v4l2_ioctl,
492 .release = v4l2_release,
510 static int get_index(
struct video_device *vdev)
524 if (video_device[i] !=
NULL &&
525 video_device[i]->parent == vdev->
parent) {
533 #define SET_VALID_IOCTL(ops, cmd, op) \
535 set_bit(_IOC_NR(cmd), valid_ioctls)
550 static void determine_valid_ioctls(
struct video_device *vdev)
598 #ifdef CONFIG_VIDEO_ADV_DEBUG
730 bitmap_andnot(vdev->valid_ioctls, valid_ioctls, vdev->valid_ioctls,
771 int minor_offset = 0;
773 const char *name_base;
785 INIT_LIST_HEAD(&vdev->
fh_list);
799 name_base =
"v4l-subdev";
821 #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
849 nr = devnode_find(vdev, nr == -1 ? 0 : nr, minor_cnt);
851 nr = devnode_find(vdev, 0, minor_cnt);
852 if (nr == minor_cnt) {
857 #ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
864 if (video_device[i] ==
NULL)
866 if (i == VIDEO_NUM_DEVICES) {
872 vdev->
minor = i + minor_offset;
878 vdev->
index = get_index(vdev);
882 determine_valid_ioctls(vdev);
890 vdev->
cdev->ops = &v4l2_fops;
901 vdev->
dev.class = &video_class;
913 vdev->
dev.release = v4l2_device_release;
915 if (nr != -1 && nr != vdev->
num && warn_if_nr_in_use)
917 name_base, nr, video_device_node_name(vdev));
923 #if defined(CONFIG_MEDIA_CONTROLLER)
935 "%s: media_device_register_entity failed\n",
942 video_device[vdev->
minor] = vdev;
969 if (!vdev || !video_is_registered(vdev))
985 static int __init videodev_init(
void)
1008 static void __exit videodev_exit(
void)