]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/media/video/omap/sensor_ov9640.c
Move i2c_driver out of ov9640_sensor structure and
[linux-2.6-omap-h63xx.git] / drivers / media / video / omap / sensor_ov9640.c
index c48f401ef923cde7c70ad437807aae6d46f5ac75..fe071e28472fed8dc46c478f0a405d31cbb21a57 100644 (file)
 #include <media/video-buf.h>
 #include <linux/delay.h>
 #include <asm/mach-types.h>
-#include <asm/arch/gpioexpander.h>
 
 #include "sensor_if.h"
 #include "ov9640.h"
+#include "h3sensorpower.h"
+#include "h4sensorpower.h"
 
 #define CAMERA_OV9640
 #ifdef CAMERA_OV9640
@@ -31,7 +32,6 @@
 struct ov9640_sensor {
        /* I2C parameters */
        struct i2c_client client;
-       struct i2c_driver driver;
        int ver; /* OV9640 version */
 };
 
@@ -669,21 +669,21 @@ ov9640_configure(struct i2c_client *client,
 static int
 ov9640_powerup(void)
 {
-       unsigned char expa;
        int err;
 
        if (machine_is_omap_h2())
                return 0;
 
-       /* read the current state of GPIO EXPA output */
-       if (( err = read_gpio_expa(&expa, 0x27))){
-               printk(KERN_ERR "Error reading GPIO EXPA \n");
-               return err;
+       if (machine_is_omap_h3()) {
+               err = h3_sensor_powerup();
+               if (err)
+                       return err;
        }
-       /* set GPIO EXPA P7 CAMERA_MOD_EN to power-up sensor */
-       if ((err = write_gpio_expa(expa | 0x80, 0x27))) {
-               printk(KERN_ERR "Error writing to GPIO EXPA \n");
-               return err;
+
+       if (machine_is_omap_h4()) {
+               err = h4_sensor_powerup();
+               if (err)
+                       return err;
        }
 
        return 0;
@@ -691,22 +691,23 @@ ov9640_powerup(void)
 static int
 ov9640_powerdown(void)
 {
-       unsigned char expa;
        int err;
 
        if (machine_is_omap_h2())
                return 0;
 
-       /* read the current state of GPIO EXPA output */
-       if (( err = read_gpio_expa(&expa, 0x27))){
-               printk(KERN_ERR "Error reading GPIO EXPA \n");
-               return err;
+       if (machine_is_omap_h3()) {
+               err = h3_sensor_powerdown();
+               if (err)
+                       return err;
        }
-       /* clear GPIO EXPA P7 CAMERA_MOD_EN to power-up sensor */
-       if ((err = write_gpio_expa(expa & ~0x80, 0x27))) {
-               printk(KERN_ERR "Error writing to GPIO EXPA \n");
-               return err;
+
+       if (machine_is_omap_h4()) {
+               err = h4_sensor_powerdown();
+               if (err)
+                       return err;
        }
+
        return 0;
 }
 
@@ -761,6 +762,8 @@ ov9640_detect(struct i2c_client *client)
        return ver;
 }
 
+static struct i2c_driver ov9640sensor_i2c_driver;
+
 /* This function registers an I2C client via i2c_attach_client() for an OV9640 
  * sensor device.  If 'probe' is non-zero, then the I2C client is only 
  * registered if the device can be detected.  If 'probe' is zero, then no 
@@ -779,8 +782,7 @@ ov9640_i2c_attach_client(struct i2c_adapter *adap, int addr, int probe)
                return -EBUSY;  /* our client is already attached */
 
        client->addr = addr;
-       client->flags = I2C_CLIENT_ALLOW_USE;
-       client->driver = &sensor->driver;
+       client->driver = &ov9640sensor_i2c_driver;
        client->adapter = adap;
 
        err = i2c_attach_client(client);
@@ -1093,12 +1095,23 @@ ov9640sensor_cleanup(void *priv)
        struct ov9640_sensor *sensor = (struct ov9640_sensor *) priv;
 
        if (sensor) {
-               i2c_del_driver(&sensor->driver);
+               i2c_del_driver(&ov9640sensor_i2c_driver);
                ov9640_powerdown();
        }
        return 0;
 }
 
+
+static struct i2c_driver ov9640sensor_i2c_driver = {
+       .driver {
+               .name           = "ov9640",
+       },
+       .id             = I2C_DRIVERID_MISC, /*FIXME:accroding to i2c-ids.h */
+       .attach_adapter = ov9640_i2c_probe_adapter,
+       .detach_client  = ov9640_i2c_detach_client,
+};
+
+
 /* Initialize the OV9640 sensor.
  * This routine allocates and initializes the data structure for the sensor, 
  * powers up the sensor, registers the I2C driver, and sets a default image 
@@ -1111,7 +1124,6 @@ static void *
 ov9640sensor_init(struct v4l2_pix_format *pix)
 {
        struct ov9640_sensor *sensor = &ov9640;
-       struct i2c_driver *driver = &sensor->driver;
        int err;
 
        memset(sensor, 0, sizeof(*sensor));
@@ -1120,14 +1132,7 @@ ov9640sensor_init(struct v4l2_pix_format *pix)
        if (ov9640_powerup())
                return NULL;
 
-       driver->owner = THIS_MODULE;
-       strlcpy(driver->name, "OV9640 I2C driver", sizeof(driver->name));
-       driver->id = I2C_DRIVERID_EXP0;
-       driver->flags = I2C_DF_NOTIFY;
-       driver->attach_adapter = ov9640_i2c_probe_adapter;
-       driver->detach_client = ov9640_i2c_detach_client;
-
-       err = i2c_add_driver(driver);
+       err = i2c_add_driver(&ov9640sensor_i2c_driver);
        if (err) {
                printk(KERN_ERR "Failed to register OV9640 I2C client.\n");
                return NULL;
@@ -1152,19 +1157,19 @@ ov9640sensor_init(struct v4l2_pix_format *pix)
 }
 
 struct camera_sensor camera_sensor_if = {
-       version:        0x01,
-       name:           "OV9640",
-       init:           ov9640sensor_init,
-       cleanup:        ov9640sensor_cleanup, 
-       enum_pixformat: ov9640sensor_enum_pixformat,
-       try_format:     ov9640sensor_try_format,
-       calc_xclk:      ov9640sensor_calc_xclk,
-       configure:      ov9640sensor_configure,
-       query_control:  ov9640sensor_query_control, 
-       get_control:    ov9640sensor_get_control, 
-       set_control:    ov9640sensor_set_control,
-       power_on:       ov9640sensor_power_on,
-       power_off:      ov9640sensor_power_off,
+       .version        = 0x01,
+       .name           = "OV9640",
+       .init           = ov9640sensor_init,
+       .cleanup        = ov9640sensor_cleanup,
+       .enum_pixformat = ov9640sensor_enum_pixformat,
+       .try_format     = ov9640sensor_try_format,
+       .calc_xclk      = ov9640sensor_calc_xclk,
+       .configure      = ov9640sensor_configure,
+       .query_control  = ov9640sensor_query_control,
+       .get_control    = ov9640sensor_get_control,
+       .set_control    = ov9640sensor_set_control,
+       .power_on       = ov9640sensor_power_on,
+       .power_off      = ov9640sensor_power_off,
 };
 
 void print_ov9640_regs(void *priv)