diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2009-12-09 06:40:05 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-22 03:53:18 -0400 |
commit | 95db3a60e0652a52df145aacade1a88c5acef659 (patch) | |
tree | 7b8a14a964684ecd49667125e5429360e41c11d5 | |
parent | e02188c90f6ef61f0844c42508fe603c5d4fa42b (diff) |
[media] v4l: Add a media_device pointer to the v4l2_device structure
The pointer will later be used to register/unregister media entities
when registering/unregistering a v4l2_subdev or a video_device.
With the introduction of media devices, device drivers need to store a
pointer to a driver-specific structure in the device's drvdata.
v4l2_device can't claim ownership of the drvdata anymore.
To maintain compatibility with drivers that rely on v4l2_device storing
a pointer to itself in the device's drvdata, v4l2_device_register() will
keep doing so if the drvdata is NULL.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | Documentation/video4linux/v4l2-framework.txt | 17 | ||||
-rw-r--r-- | drivers/media/video/v4l2-device.c | 13 | ||||
-rw-r--r-- | include/media/v4l2-device.h | 4 |
3 files changed, 23 insertions, 11 deletions
diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index eb8479565dc4..7de55cfae04e 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt | |||
@@ -83,11 +83,17 @@ You must register the device instance: | |||
83 | 83 | ||
84 | v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); | 84 | v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); |
85 | 85 | ||
86 | Registration will initialize the v4l2_device struct and link dev->driver_data | 86 | Registration will initialize the v4l2_device struct. If the dev->driver_data |
87 | to v4l2_dev. If v4l2_dev->name is empty then it will be set to a value derived | 87 | field is NULL, it will be linked to v4l2_dev. Drivers that use the media |
88 | from dev (driver name followed by the bus_id, to be precise). If you set it | 88 | device framework in addition to the V4L2 framework need to set |
89 | up before calling v4l2_device_register then it will be untouched. If dev is | 89 | dev->driver_data manually to point to the driver-specific device structure |
90 | NULL, then you *must* setup v4l2_dev->name before calling v4l2_device_register. | 90 | that embed the struct v4l2_device instance. This is achieved by a |
91 | dev_set_drvdata() call before registering the V4L2 device instance. | ||
92 | |||
93 | If v4l2_dev->name is empty then it will be set to a value derived from dev | ||
94 | (driver name followed by the bus_id, to be precise). If you set it up before | ||
95 | calling v4l2_device_register then it will be untouched. If dev is NULL, then | ||
96 | you *must* setup v4l2_dev->name before calling v4l2_device_register. | ||
91 | 97 | ||
92 | You can use v4l2_device_set_name() to set the name based on a driver name and | 98 | You can use v4l2_device_set_name() to set the name based on a driver name and |
93 | a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1, | 99 | a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1, |
@@ -108,6 +114,7 @@ You unregister with: | |||
108 | 114 | ||
109 | v4l2_device_unregister(struct v4l2_device *v4l2_dev); | 115 | v4l2_device_unregister(struct v4l2_device *v4l2_dev); |
110 | 116 | ||
117 | If the dev->driver_data field points to v4l2_dev, it will be reset to NULL. | ||
111 | Unregistering will also automatically unregister all subdevs from the device. | 118 | Unregistering will also automatically unregister all subdevs from the device. |
112 | 119 | ||
113 | If you have a hotpluggable device (e.g. a USB device), then when a disconnect | 120 | If you have a hotpluggable device (e.g. a USB device), then when a disconnect |
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c index 8c0ad8b372d8..cfbd8a38991d 100644 --- a/drivers/media/video/v4l2-device.c +++ b/drivers/media/video/v4l2-device.c | |||
@@ -47,9 +47,8 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) | |||
47 | if (!v4l2_dev->name[0]) | 47 | if (!v4l2_dev->name[0]) |
48 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s", | 48 | snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s", |
49 | dev->driver->name, dev_name(dev)); | 49 | dev->driver->name, dev_name(dev)); |
50 | if (dev_get_drvdata(dev)) | 50 | if (!dev_get_drvdata(dev)) |
51 | v4l2_warn(v4l2_dev, "Non-NULL drvdata on register\n"); | 51 | dev_set_drvdata(dev, v4l2_dev); |
52 | dev_set_drvdata(dev, v4l2_dev); | ||
53 | return 0; | 52 | return 0; |
54 | } | 53 | } |
55 | EXPORT_SYMBOL_GPL(v4l2_device_register); | 54 | EXPORT_SYMBOL_GPL(v4l2_device_register); |
@@ -72,10 +71,12 @@ EXPORT_SYMBOL_GPL(v4l2_device_set_name); | |||
72 | 71 | ||
73 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev) | 72 | void v4l2_device_disconnect(struct v4l2_device *v4l2_dev) |
74 | { | 73 | { |
75 | if (v4l2_dev->dev) { | 74 | if (v4l2_dev->dev == NULL) |
75 | return; | ||
76 | |||
77 | if (dev_get_drvdata(v4l2_dev->dev) == v4l2_dev) | ||
76 | dev_set_drvdata(v4l2_dev->dev, NULL); | 78 | dev_set_drvdata(v4l2_dev->dev, NULL); |
77 | v4l2_dev->dev = NULL; | 79 | v4l2_dev->dev = NULL; |
78 | } | ||
79 | } | 80 | } |
80 | EXPORT_SYMBOL_GPL(v4l2_device_disconnect); | 81 | EXPORT_SYMBOL_GPL(v4l2_device_disconnect); |
81 | 82 | ||
diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h index 78b11e5a6db7..0c2bd3075038 100644 --- a/include/media/v4l2-device.h +++ b/include/media/v4l2-device.h | |||
@@ -21,6 +21,7 @@ | |||
21 | #ifndef _V4L2_DEVICE_H | 21 | #ifndef _V4L2_DEVICE_H |
22 | #define _V4L2_DEVICE_H | 22 | #define _V4L2_DEVICE_H |
23 | 23 | ||
24 | #include <media/media-device.h> | ||
24 | #include <media/v4l2-subdev.h> | 25 | #include <media/v4l2-subdev.h> |
25 | 26 | ||
26 | /* Each instance of a V4L2 device should create the v4l2_device struct, | 27 | /* Each instance of a V4L2 device should create the v4l2_device struct, |
@@ -39,6 +40,9 @@ struct v4l2_device { | |||
39 | Note: dev might be NULL if there is no parent device | 40 | Note: dev might be NULL if there is no parent device |
40 | as is the case with e.g. ISA devices. */ | 41 | as is the case with e.g. ISA devices. */ |
41 | struct device *dev; | 42 | struct device *dev; |
43 | #if defined(CONFIG_MEDIA_CONTROLLER) | ||
44 | struct media_device *mdev; | ||
45 | #endif | ||
42 | /* used to keep track of the registered subdevs */ | 46 | /* used to keep track of the registered subdevs */ |
43 | struct list_head subdevs; | 47 | struct list_head subdevs; |
44 | /* lock this struct; can be used by the driver as well if this | 48 | /* lock this struct; can be used by the driver as well if this |