diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2008-07-17 18:45:00 +0200 |
---|---|---|
committer | Hans Verkuil <hverkuil@xs4all.nl> | 2008-07-17 18:45:00 +0200 |
commit | ad2b972483262f7b5865dbfc824303de2c82b3aa (patch) | |
tree | f57077fd117283d8bd03d1fa93e38fd08de14c82 /linux | |
parent | 7b7b6e145e1bf05cdf3e5d82e8f30b288ad9e15a (diff) | |
download | mediapointer-dvb-s2-ad2b972483262f7b5865dbfc824303de2c82b3aa.tar.gz mediapointer-dvb-s2-ad2b972483262f7b5865dbfc824303de2c82b3aa.tar.bz2 |
videodev: add support for kernels < 2.6.19
From: Hans Verkuil <hverkuil@xs4all.nl>
Add the necessary compatibility code to handle the struct device/struct class_device
differences.
It was too much work (with uncertain benefits) to convert several drivers
to handle kernels <2.6.19, so they are not built on these older kernels.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Diffstat (limited to 'linux')
-rw-r--r-- | linux/drivers/media/video/videodev.c | 80 | ||||
-rw-r--r-- | linux/include/media/v4l2-dev.h | 24 |
2 files changed, 91 insertions, 13 deletions
diff --git a/linux/drivers/media/video/videodev.c b/linux/drivers/media/video/videodev.c index a3010740a..fa6f44fdb 100644 --- a/linux/drivers/media/video/videodev.c +++ b/linux/drivers/media/video/videodev.c @@ -376,6 +376,7 @@ EXPORT_SYMBOL(v4l_printk_ioctl); * sysfs stuff */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) static ssize_t show_index(struct device *cd, struct device_attribute *attr, char *buf) { @@ -392,6 +393,30 @@ static ssize_t show_name(struct device *cd, return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name); } +static struct device_attribute video_device_attrs[] = { + __ATTR(name, S_IRUGO, show_name, NULL), + __ATTR(index, S_IRUGO, show_index, NULL), + __ATTR_NULL +}; +#else +static ssize_t show_index(struct class_device *cd, char *buf) +{ + struct video_device *vfd = container_of(cd, struct video_device, + class_dev); + return sprintf(buf, "%i\n", vfd->index); +} + +static ssize_t show_name(struct class_device *cd, char *buf) +{ + struct video_device *vfd = container_of(cd, struct video_device, + class_dev); + return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name); +} + +static CLASS_DEVICE_ATTR(index, S_IRUGO, show_index, NULL); +static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL); +#endif + struct video_device *video_device_alloc(void) { struct video_device *vfd; @@ -407,7 +432,11 @@ void video_device_release(struct video_device *vfd) } EXPORT_SYMBOL(video_device_release); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) +static void video_release(struct class_device *cd) +#else static void video_release(struct device *cd) +#endif { struct video_device *vfd = container_of(cd, struct video_device, class_dev); @@ -420,16 +449,14 @@ static void video_release(struct device *cd) vfd->release(vfd); } -static struct device_attribute video_device_attrs[] = { - __ATTR(name, S_IRUGO, show_name, NULL), - __ATTR(index, S_IRUGO, show_index, NULL), - __ATTR_NULL -}; - static struct class video_class = { .name = VIDEO_NAME, +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) + .release = video_release, +#else .dev_attrs = video_device_attrs, .dev_release = video_release, +#endif }; /* @@ -2188,8 +2215,7 @@ int video_register_device_index(struct video_device *vfd, int type, int nr, ret = 0; #endif if (ret < 0) { - printk(KERN_ERR "%s: get_index failed\n", - __func__); + printk(KERN_ERR "%s: get_index failed\n", __func__); goto fail_minor; } @@ -2200,17 +2226,43 @@ int video_register_device_index(struct video_device *vfd, int type, int nr, /* sysfs class */ memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev)); - if (vfd->dev) - vfd->class_dev.parent = vfd->dev; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) vfd->class_dev.class = &video_class; vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) + if (vfd->dev) + vfd->class_dev.dev = vfd->dev; + sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base); + ret = class_device_register(&vfd->class_dev); +#else + if (vfd->dev) + vfd->class_dev.parent = vfd->dev; sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base); ret = device_register(&vfd->class_dev); +#endif + if (ret < 0) { + printk(KERN_ERR "%s: device_register failed\n", __func__); + goto fail_minor; + } +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) + ret = class_device_create_file(&vfd->class_dev, + &class_device_attr_name); if (ret < 0) { - printk(KERN_ERR "%s: device_register failed\n", - __func__); + printk(KERN_ERR "%s: class_device_create_file 'name' failed\n", + __func__); + class_device_unregister(&vfd->class_dev); goto fail_minor; } + ret = class_device_create_file(&vfd->class_dev, + &class_device_attr_index); + if (ret < 0) { + printk(KERN_ERR "%s: class_device_create_file 'index' failed\n", + __func__); + class_device_unregister(&vfd->class_dev); + goto fail_minor; + } +#endif #if 1 /* keep */ /* needed until all drivers are fixed */ @@ -2245,7 +2297,11 @@ void video_unregister_device(struct video_device *vfd) panic("videodev: bad unregister"); video_device[vfd->minor]=NULL; +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) + class_device_unregister(&vfd->class_dev); +#else device_unregister(&vfd->class_dev); +#endif mutex_unlock(&videodev_lock); } EXPORT_SYMBOL(video_unregister_device); diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 2d68db550..798622258 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -88,7 +88,11 @@ struct video_device const struct file_operations *fops; /* sysfs */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) struct device class_dev; /* v4l device */ +#else + struct class_device class_dev; +#endif struct device *dev; /* device parent */ /* device info */ @@ -379,13 +383,30 @@ extern int video_usercopy(struct inode *inode, struct file *file, #ifdef CONFIG_VIDEO_V4L1_COMPAT #include <linux/mm.h> +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) +static inline int __must_check +video_device_create_file(struct video_device *vfd, + struct class_device_attribute *attr) +{ + int ret = class_device_create_file(&vfd->class_dev, attr); + if (ret < 0) + printk(KERN_WARNING "%s error: %d\n", __func__, ret); + return ret; +} +static inline void +video_device_remove_file(struct video_device *vfd, + struct class_device_attribute *attr) +{ + class_device_remove_file(&vfd->class_dev, attr); +} +#else static inline int __must_check video_device_create_file(struct video_device *vfd, struct device_attribute *attr) { int ret = device_create_file(&vfd->class_dev, attr); if (ret < 0) - printk(KERN_WARNING "%s error: %d\n", __FUNCTION__, ret); + printk(KERN_WARNING "%s error: %d\n", __func__, ret); return ret; } static inline void @@ -394,6 +415,7 @@ video_device_remove_file(struct video_device *vfd, { device_remove_file(&vfd->class_dev, attr); } +#endif #endif /* CONFIG_VIDEO_V4L1_COMPAT */ |