V4L/DVB (11607): soc-camera: add a free_bus method to struct soc_camera_link
authorGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Fri, 24 Apr 2009 15:53:51 +0000 (12:53 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 16 Jun 2009 21:20:43 +0000 (18:20 -0300)
Currently pcm990 camera bus-width management functions request a GPIO and never
free it again. With this approach the GPIO extender driver cannot be unloaded
once camera drivers have been loaded, also unloading theb i2c-pxa bus driver
produces errors, because the GPIO extender driver cannot unregister properly.
Another problem is, that if camera drivers are once loaded before the GPIO
extender driver, the platform code marks the GPIO unavailable and only a reboot
helps to recover. Adding an explicit free_bus method and using it in mt9m001
and mt9v022 drivers fixes these problems.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
arch/arm/mach-pxa/pcm990-baseboard.c
drivers/media/video/mt9m001.c
drivers/media/video/mt9v022.c
include/media/soc_camera.h

index 095521e9ee246755980af5a59f76986f89ecb59c..01791d74e08ec543e6aab65394c137921a6552f4 100644 (file)
@@ -380,12 +380,12 @@ static struct pca953x_platform_data pca9536_data = {
        .gpio_base      = NR_BUILTIN_GPIO,
 };
 
-static int gpio_bus_switch;
+static int gpio_bus_switch = -EINVAL;
 
 static int pcm990_camera_set_bus_param(struct soc_camera_link *link,
-               unsigned long flags)
+                                      unsigned long flags)
 {
-       if (gpio_bus_switch <= 0) {
+       if (gpio_bus_switch < 0) {
                if (flags == SOCAM_DATAWIDTH_10)
                        return 0;
                else
@@ -404,25 +404,34 @@ static unsigned long pcm990_camera_query_bus_param(struct soc_camera_link *link)
 {
        int ret;
 
-       if (!gpio_bus_switch) {
+       if (gpio_bus_switch < 0) {
                ret = gpio_request(NR_BUILTIN_GPIO, "camera");
                if (!ret) {
                        gpio_bus_switch = NR_BUILTIN_GPIO;
                        gpio_direction_output(gpio_bus_switch, 0);
-               } else
-                       gpio_bus_switch = -EINVAL;
+               }
        }
 
-       if (gpio_bus_switch > 0)
+       if (gpio_bus_switch >= 0)
                return SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_10;
        else
                return SOCAM_DATAWIDTH_10;
 }
 
+static void pcm990_camera_free_bus(struct soc_camera_link *link)
+{
+       if (gpio_bus_switch < 0)
+               return;
+
+       gpio_free(gpio_bus_switch);
+       gpio_bus_switch = -EINVAL;
+}
+
 static struct soc_camera_link iclink = {
        .bus_id = 0, /* Must match with the camera ID above */
        .query_bus_param = pcm990_camera_query_bus_param,
        .set_bus_param = pcm990_camera_set_bus_param,
+       .free_bus = pcm990_camera_free_bus,
 };
 
 /* Board I2C devices. */
index 684f62fa7897586152db543a6a3c95069dea7cf0..3838ff77381b89cecb7d0e120ab5e87dd8d5605f 100644 (file)
@@ -604,10 +604,13 @@ ei2c:
 static void mt9m001_video_remove(struct soc_camera_device *icd)
 {
        struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+       struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
 
        dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9m001->client->addr,
                icd->dev.parent, icd->vdev);
        soc_camera_video_stop(icd);
+       if (icl->free_bus)
+               icl->free_bus(icl);
 }
 
 static int mt9m001_probe(struct i2c_client *client,
index 4d3b4813c322e67dc46c2c8c272a8db1ba1c728f..412b399baca40c58ce13729b922b250b6ba4ab07 100644 (file)
@@ -735,10 +735,13 @@ ei2c:
 static void mt9v022_video_remove(struct soc_camera_device *icd)
 {
        struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
+       struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
 
        dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9v022->client->addr,
                icd->dev.parent, icd->vdev);
        soc_camera_video_stop(icd);
+       if (icl->free_bus)
+               icl->free_bus(icl);
 }
 
 static int mt9v022_probe(struct i2c_client *client,
index 37013688af44b64c8107e94fa7e416411e69dcfa..396c32550e0424a9b223341cd11abe8b99f35435 100644 (file)
@@ -107,6 +107,7 @@ struct soc_camera_link {
         */
        int (*set_bus_param)(struct soc_camera_link *, unsigned long flags);
        unsigned long (*query_bus_param)(struct soc_camera_link *);
+       void (*free_bus)(struct soc_camera_link *);
 };
 
 static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)