From b43528c7ba3da6f260cd3de6ca21c991a012fa6e Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sat, 23 Aug 2008 10:34:55 +0200 Subject: v4l2-dev: remove obsolete video_exclusive_open/release From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/include/media/v4l2-dev.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 4e1511b0b..cee043d6a 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -81,10 +81,6 @@ struct video_device * Or use {pci|usb}_{get|set}_drvdata() directly. */ void *priv; #endif - - /* for videodev.c internal usage -- please don't touch */ - int users; /* video_exclusive_{open|close} ... */ - struct mutex lock; /* ... helper function uses these */ }; /* Class-dev to video-device */ @@ -115,8 +111,6 @@ static inline void video_set_drvdata(struct video_device *dev, void *data) /* Obsolete stuff - Still needed for radio devices and obsolete drivers */ extern struct video_device* video_devdata(struct file*); -extern int video_exclusive_open(struct inode *inode, struct file *file); -extern int video_exclusive_release(struct inode *inode, struct file *file); #endif #endif /* _V4L2_DEV_H */ -- cgit v1.2.3 From 79721c4957171ea0fdaf1fa6565e7699dad1b76e Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sat, 23 Aug 2008 10:47:41 +0200 Subject: v4l2-dev: add video_device_release_empty From: Hans Verkuil Add a second release function: video_device_release_empty It can be used by drivers that have statically allocated video_device structs. Its use usually, but not always, indicates laziness on the part of the driver programmer. Priority: normal Signed-off-by: Hans Verkuil --- linux/include/media/v4l2-dev.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index cee043d6a..b6f00b933 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -95,7 +95,12 @@ void video_unregister_device(struct video_device *); /* helper functions to alloc / release struct video_device, the later can be used for video_device->release() */ struct video_device *video_device_alloc(void); +/* this release function frees the vfd pointer */ void video_device_release(struct video_device *vfd); +/* this release function does nothing, use when the video_device is a + static global struct. Note that having a static video_device is + a dubious construction at best. */ +void video_device_release_empty(struct video_device *vfd); #ifdef OBSOLETE_DEVDATA /* to be removed soon */ /* helper functions to access driver private data. */ -- cgit v1.2.3 From 60c4198b31349257aac0d357d2026f7a10b8a4e8 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sat, 23 Aug 2008 11:38:11 +0200 Subject: v4l2: add __must_check to v4l2_dev.h From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/include/media/v4l2-dev.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index b6f00b933..67450f291 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -87,14 +87,14 @@ struct video_device #define to_video_device(cd) container_of(cd, struct video_device, dev) /* Version 2 functions */ -extern int video_register_device(struct video_device *vfd, int type, int nr); -int video_register_device_index(struct video_device *vfd, int type, int nr, +int __must_check video_register_device(struct video_device *vfd, int type, int nr); +int __must_check video_register_device_index(struct video_device *vfd, int type, int nr, int index); void video_unregister_device(struct video_device *); /* helper functions to alloc / release struct video_device, the later can be used for video_device->release() */ -struct video_device *video_device_alloc(void); +struct video_device * __must_check video_device_alloc(void); /* this release function frees the vfd pointer */ void video_device_release(struct video_device *vfd); /* this release function does nothing, use when the video_device is a -- cgit v1.2.3 From da4e1aee344454f87d08d5914da4ec98f9824bdc Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sat, 23 Aug 2008 12:24:07 +0200 Subject: v4l2: remove the priv field, use dev_get_drvdata instead From: Hans Verkuil Remove the priv field and let video_get/set_drvdata use dev_get_drvdata and dev_set_drvdata instead. Convert all drivers that still used priv directly. Priority: normal Signed-off-by: Hans Verkuil --- linux/include/media/v4l2-dev.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 67450f291..926d74551 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -73,14 +73,6 @@ struct video_device /* ioctl callbacks */ const struct v4l2_ioctl_ops *ioctl_ops; - -#ifdef OBSOLETE_DEVDATA /* to be removed soon */ - /* dev->driver_data will be used instead some day. - * Use the video_{get|set}_drvdata() helper functions, - * so the switch over will be transparent for you. - * Or use {pci|usb}_{get|set}_drvdata() directly. */ - void *priv; -#endif }; /* Class-dev to video-device */ @@ -102,18 +94,18 @@ void video_device_release(struct video_device *vfd); a dubious construction at best. */ void video_device_release_empty(struct video_device *vfd); -#ifdef OBSOLETE_DEVDATA /* to be removed soon */ /* helper functions to access driver private data. */ static inline void *video_get_drvdata(struct video_device *dev) { - return dev->priv; + return dev_get_drvdata(&dev->dev); } static inline void video_set_drvdata(struct video_device *dev, void *data) { - dev->priv = data; + dev_set_drvdata(&dev->dev, data); } +#ifdef OBSOLETE_DEVDATA /* to be removed soon */ /* Obsolete stuff - Still needed for radio devices and obsolete drivers */ extern struct video_device* video_devdata(struct file*); #endif -- cgit v1.2.3 From 7940e700c970556739f490ef6293d03612eb02a9 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sat, 23 Aug 2008 12:48:38 +0200 Subject: v4l2-dev: cleanups and add video_drvdata helper function From: Hans Verkuil Cleanup v4l2-dev.[ch], add/improve comments and add a new helper function: video_drvdata() that can get the private driver data from a file struct. Priority: normal Signed-off-by: Hans Verkuil --- linux/include/media/v4l2-dev.h | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 926d74551..8252d36ec 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -9,16 +9,14 @@ #ifndef _V4L2_DEV_H #define _V4L2_DEV_H -#define OBSOLETE_DEVDATA 1 /* to be removed soon */ - #include #include #include #include -#include /* need __user */ #include #define VIDEO_MAJOR 81 + /* Minor device allocation */ #define MINOR_VFL_TYPE_GRABBER_MIN 0 #define MINOR_VFL_TYPE_GRABBER_MAX 63 @@ -75,20 +73,25 @@ struct video_device const struct v4l2_ioctl_ops *ioctl_ops; }; -/* Class-dev to video-device */ +/* dev to video-device */ #define to_video_device(cd) container_of(cd, struct video_device, dev) -/* Version 2 functions */ +/* Register and unregister devices. Note that if video_register_device fails, + the release() callback of the video_device structure is *not* called, so + the caller is responsible for freeing any data. Usually that means that + you call video_device_release() on failure. */ int __must_check video_register_device(struct video_device *vfd, int type, int nr); -int __must_check video_register_device_index(struct video_device *vfd, int type, int nr, - int index); -void video_unregister_device(struct video_device *); +int __must_check video_register_device_index(struct video_device *vfd, + int type, int nr, int index); +void video_unregister_device(struct video_device *vfd); -/* helper functions to alloc / release struct video_device, the - later can be used for video_device->release() */ +/* helper functions to alloc/release struct video_device, the + latter can also be used for video_device->release(). */ struct video_device * __must_check video_device_alloc(void); + /* this release function frees the vfd pointer */ void video_device_release(struct video_device *vfd); + /* this release function does nothing, use when the video_device is a static global struct. Note that having a static video_device is a dubious construction at best. */ @@ -105,9 +108,13 @@ static inline void video_set_drvdata(struct video_device *dev, void *data) dev_set_drvdata(&dev->dev, data); } -#ifdef OBSOLETE_DEVDATA /* to be removed soon */ -/* Obsolete stuff - Still needed for radio devices and obsolete drivers */ -extern struct video_device* video_devdata(struct file*); -#endif +struct video_device *video_devdata(struct file *file); + +/* Combine video_get_drvdata and video_devdata as this is + used very often. */ +static inline void *video_drvdata(struct file *file) +{ + return video_get_drvdata(video_devdata(file)); +} #endif /* _V4L2_DEV_H */ -- cgit v1.2.3 From 59a57f6b9ea53f0ff73ec4eafbab23f2dea7221e Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Mon, 11 Aug 2008 03:39:09 +0200 Subject: v4l2-dev: video_get/set_drvdata needs to use class_get/set_devdata for < 2.6.19 From: Hans Verkuil Priority: normal Signed-off-by: Hans Verkuil --- linux/include/media/v4l2-dev.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 8252d36ec..ba05b8164 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -100,12 +100,20 @@ void video_device_release_empty(struct video_device *vfd); /* helper functions to access driver private data. */ static inline void *video_get_drvdata(struct video_device *dev) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) + return class_get_devdata(&dev->dev); +#else return dev_get_drvdata(&dev->dev); +#endif } static inline void video_set_drvdata(struct video_device *dev, void *data) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) + class_set_devdata(&dev->dev, data); +#else dev_set_drvdata(&dev->dev, data); +#endif } struct video_device *video_devdata(struct file *file); -- cgit v1.2.3 From 937ba8f2a0dc3b8cdb98de9a48c256ad24427ac9 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 29 Aug 2008 22:31:35 +0200 Subject: v4l2: use register_chrdev_region instead of register_chrdev From: Hans Verkuil Replace the old register_chrdev with the more flexible register_chrdev_region. Ensure that the release() is called when the very last chardev usage was released, and not when the sysfs devices were removed. This should simplify hotpluggable drivers considerably. Tested-by: Mike Isely Tested-by: Laurent Pinchart Priority: normal Signed-off-by: Hans Verkuil Acked-by: David Ellingsworth Reviewed-by: Hans de Goede --- linux/include/media/v4l2-dev.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'linux/include/media') diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index ba05b8164..9158ad8b5 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -51,6 +52,8 @@ struct video_device #else struct class_device dev; #endif + struct cdev cdev; /* character device */ + void (*cdev_release)(struct kobject *kobj); struct device *parent; /* device parent */ /* device info */ -- cgit v1.2.3