linux-omap 2.6.37: sync with OE .dev
[glsdk/meta-ti-glsdk.git] / recipes-bsp / linux / linux-omap / media / 0017-v4l-Add-a-media_device-pointer-to-the-v4l2_device-st.patch
1 From 56e006c01032f98483195e572700e17fb8aaa8b1 Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Wed, 9 Dec 2009 12:40:05 +0100
4 Subject: [PATCH 17/43] v4l: Add a media_device pointer to the v4l2_device structure
6 The pointer will later be used to register/unregister media entities
7 when registering/unregistering a v4l2_subdev or a video_device.
9 With the introduction of media devices, device drivers need to store a
10 pointer to a driver-specific structure in the device's drvdata.
11 v4l2_device can't claim ownership of the drvdata anymore.
13 To maintain compatibility with drivers that rely on v4l2_device storing
14 a pointer to itself in the device's drvdata, v4l2_device_register() will
15 keep doing so if the drvdata is NULL.
17 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
18 ---
19  Documentation/video4linux/v4l2-framework.txt |   17 ++++++++++++-----
20  drivers/media/video/v4l2-device.c            |   13 +++++++------
21  include/media/v4l2-device.h                  |    4 ++++
22  3 files changed, 23 insertions(+), 11 deletions(-)
24 diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt
25 index 4db1def..aeb2a22 100644
26 --- a/Documentation/video4linux/v4l2-framework.txt
27 +++ b/Documentation/video4linux/v4l2-framework.txt
28 @@ -83,11 +83,17 @@ You must register the device instance:
29  
30         v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev);
31  
32 -Registration will initialize the v4l2_device struct and link dev->driver_data
33 -to v4l2_dev. If v4l2_dev->name is empty then it will be set to a value derived
34 -from dev (driver name followed by the bus_id, to be precise). If you set it
35 -up before calling v4l2_device_register then it will be untouched. If dev is
36 -NULL, then you *must* setup v4l2_dev->name before calling v4l2_device_register.
37 +Registration will initialize the v4l2_device struct. If the dev->driver_data
38 +field is NULL, it will be linked to v4l2_dev. Drivers that use the media
39 +device framework in addition to the V4L2 framework need to set
40 +dev->driver_data manually to point to the driver-specific device structure
41 +that embed the struct v4l2_device instance. This is achieved by a
42 +dev_set_drvdata() call before registering the V4L2 device instance.
43 +
44 +If v4l2_dev->name is empty then it will be set to a value derived from dev
45 +(driver name followed by the bus_id, to be precise). If you set it up before
46 +calling v4l2_device_register then it will be untouched. If dev is NULL, then
47 +you *must* setup v4l2_dev->name before calling v4l2_device_register.
48  
49  You can use v4l2_device_set_name() to set the name based on a driver name and
50  a driver-global atomic_t instance. This will generate names like ivtv0, ivtv1,
51 @@ -108,6 +114,7 @@ You unregister with:
52  
53         v4l2_device_unregister(struct v4l2_device *v4l2_dev);
54  
55 +If the dev->driver_data field points to v4l2_dev, it will be reset to NULL.
56  Unregistering will also automatically unregister all subdevs from the device.
57  
58  If you have a hotpluggable device (e.g. a USB device), then when a disconnect
59 diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
60 index 97e84df..5c16a12 100644
61 --- a/drivers/media/video/v4l2-device.c
62 +++ b/drivers/media/video/v4l2-device.c
63 @@ -47,9 +47,8 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
64         if (!v4l2_dev->name[0])
65                 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",
66                         dev->driver->name, dev_name(dev));
67 -       if (dev_get_drvdata(dev))
68 -               v4l2_warn(v4l2_dev, "Non-NULL drvdata on register\n");
69 -       dev_set_drvdata(dev, v4l2_dev);
70 +       if (!dev_get_drvdata(dev))
71 +               dev_set_drvdata(dev, v4l2_dev);
72         return 0;
73  }
74  EXPORT_SYMBOL_GPL(v4l2_device_register);
75 @@ -72,10 +71,12 @@ EXPORT_SYMBOL_GPL(v4l2_device_set_name);
76  
77  void v4l2_device_disconnect(struct v4l2_device *v4l2_dev)
78  {
79 -       if (v4l2_dev->dev) {
80 +       if (v4l2_dev->dev == NULL)
81 +               return;
82 +
83 +       if (dev_get_drvdata(v4l2_dev->dev) == v4l2_dev)
84                 dev_set_drvdata(v4l2_dev->dev, NULL);
85 -               v4l2_dev->dev = NULL;
86 -       }
87 +       v4l2_dev->dev = NULL;
88  }
89  EXPORT_SYMBOL_GPL(v4l2_device_disconnect);
90  
91 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
92 index b16f307..759db73 100644
93 --- a/include/media/v4l2-device.h
94 +++ b/include/media/v4l2-device.h
95 @@ -21,6 +21,7 @@
96  #ifndef _V4L2_DEVICE_H
97  #define _V4L2_DEVICE_H
98  
99 +#include <media/media-device.h>
100  #include <media/v4l2-subdev.h>
101  
102  /* Each instance of a V4L2 device should create the v4l2_device struct,
103 @@ -39,6 +40,9 @@ struct v4l2_device {
104            Note: dev might be NULL if there is no parent device
105            as is the case with e.g. ISA devices. */
106         struct device *dev;
107 +#if defined(CONFIG_MEDIA_CONTROLLER)
108 +       struct media_device *mdev;
109 +#endif
110         /* used to keep track of the registered subdevs */
111         struct list_head subdevs;
112         /* lock this struct; can be used by the driver as well if this
113 -- 
114 1.6.6.1