V4L/DVB: sn9c102: Make hv7131d sensor code also recognize the HV7131E
[safe/jmp/linux-2.6] / drivers / media / video / sn9c102 / sn9c102_hv7131d.c
index c4117bf..2dce5c9 100644 (file)
@@ -1,8 +1,8 @@
 /***************************************************************************
- * Plug-in for HV7131D image sensor connected to the SN9C10x PC Camera     *
+ * Plug-in for HV7131D image sensor connected to the SN9C1xx PC Camera     *
  * Controllers                                                             *
  *                                                                         *
- * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it>  *
+ * Copyright (C) 2004-2007 by Luca Risolia <luca.risolia@studio.unibo.it>  *
  *                                                                         *
  * This program is free software; you can redistribute it and/or modify    *
  * it under the terms of the GNU General Public License as published by    *
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
-
-
-static struct sn9c102_sensor hv7131d;
+#include "sn9c102_devtable.h"
 
 
 static int hv7131d_init(struct sn9c102_device* cam)
 {
-       int err = 0;
+       int err;
 
-       err += sn9c102_write_reg(cam, 0x00, 0x10);
-       err += sn9c102_write_reg(cam, 0x00, 0x11);
-       err += sn9c102_write_reg(cam, 0x00, 0x14);
-       err += sn9c102_write_reg(cam, 0x60, 0x17);
-       err += sn9c102_write_reg(cam, 0x0e, 0x18);
-       err += sn9c102_write_reg(cam, 0xf2, 0x19);
+       err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11},
+                                      {0x00, 0x14}, {0x60, 0x17},
+                                      {0x0e, 0x18}, {0xf2, 0x19});
 
        err += sn9c102_i2c_write(cam, 0x01, 0x04);
        err += sn9c102_i2c_write(cam, 0x02, 0x00);
@@ -124,7 +119,7 @@ static int hv7131d_set_ctrl(struct sn9c102_device* cam,
 static int hv7131d_set_crop(struct sn9c102_device* cam,
                            const struct v4l2_rect* rect)
 {
-       struct sn9c102_sensor* s = &hv7131d;
+       struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
        int err = 0;
        u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 2,
           v_start = (u8)(rect->top - s->cropcap.bounds.top) + 2;
@@ -150,9 +145,10 @@ static int hv7131d_set_pix_format(struct sn9c102_device* cam,
 }
 
 
-static struct sn9c102_sensor hv7131d = {
+static const struct sn9c102_sensor hv7131d = {
        .name = "HV7131D",
        .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
+       .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
        .sysfs_ops = SN9C102_I2C_READ | SN9C102_I2C_WRITE,
        .frequency = SN9C102_I2C_100KHZ,
        .interface = SN9C102_I2C_2WIRES,
@@ -249,20 +245,17 @@ static struct sn9c102_sensor hv7131d = {
 
 int sn9c102_probe_hv7131d(struct sn9c102_device* cam)
 {
-       int r0 = 0, r1 = 0, err = 0;
+       int r0 = 0, r1 = 0, err;
 
-       err += sn9c102_write_reg(cam, 0x01, 0x01);
-       err += sn9c102_write_reg(cam, 0x00, 0x01);
-       err += sn9c102_write_reg(cam, 0x28, 0x17);
-       if (err)
-               return -EIO;
+       err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
+                                      {0x28, 0x17});
 
        r0 = sn9c102_i2c_try_read(cam, &hv7131d, 0x00);
        r1 = sn9c102_i2c_try_read(cam, &hv7131d, 0x01);
-       if (r0 < 0 || r1 < 0)
+       if (err || r0 < 0 || r1 < 0)
                return -EIO;
 
-       if (r0 != 0x00 && r1 != 0x04)
+       if ((r0 != 0x00 && r0 != 0x01) || r1 != 0x04)
                return -ENODEV;
 
        sn9c102_attach_sensor(cam, &hv7131d);