V4L/DVB (9845): gspca: Add sensor mi0360 in vc032x.
authorJean-Francois Moine <moinejf@free.fr>
Wed, 26 Nov 2008 19:17:13 +0000 (16:17 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 30 Dec 2008 11:38:48 +0000 (09:38 -0200)
Signed-off-by: Jean-Francois Moine <moinejf@free.fr>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/gspca/vc032x.c

index 17af353ddd1c872226be39550073de968b3d925b..88b5d762dea31d19f53140e83becd2f13a01aee9 100644 (file)
@@ -41,11 +41,12 @@ struct sd {
 #define BRIDGE_VC0323 1
        char sensor;
 #define SENSOR_HV7131R 0
-#define SENSOR_MI1320 1
-#define SENSOR_MI1310_SOC 2
-#define SENSOR_OV7660 3
-#define SENSOR_OV7670 4
-#define SENSOR_PO3130NC 5
+#define SENSOR_MI0360 1
+#define SENSOR_MI1320 2
+#define SENSOR_MI1310_SOC 3
+#define SENSOR_OV7660 4
+#define SENSOR_OV7670 5
+#define SENSOR_PO3130NC 6
 };
 
 /* V4L2 controls supported by the driver */
@@ -111,6 +112,239 @@ static struct v4l2_pix_format vc0323_mode[] = {
                .priv = 0},
 };
 
+static const __u8 mi0360_matrix[9] = {
+       0x50, 0xf8, 0xf8, 0xf5, 0x50, 0xfb, 0xff, 0xf1, 0x50
+};
+
+static const __u8 mi0360_initVGA_JPG[][4] = {
+       {0xb0, 0x03, 0x19, 0xcc},
+       {0xb0, 0x04, 0x02, 0xcc},
+       {0xb3, 0x00, 0x24, 0xcc},
+       {0xb3, 0x00, 0x25, 0xcc},
+       {0xb3, 0x08, 0x01, 0xcc},
+       {0xb3, 0x09, 0x0c, 0xcc},
+       {0xb3, 0x05, 0x01, 0xcc},
+       {0xb3, 0x06, 0x03, 0xcc},
+       {0xb3, 0x03, 0x0a, 0xcc},
+       {0xb3, 0x20, 0x00, 0xcc},
+       {0xb3, 0x21, 0x00, 0xcc},
+       {0xb3, 0x22, 0x01, 0xcc},
+       {0xb3, 0x23, 0xe0, 0xcc},
+       {0xb3, 0x04, 0x05, 0xcc},
+       {0xb3, 0x14, 0x00, 0xcc},
+       {0xb3, 0x15, 0x00, 0xcc},
+       {0xb3, 0x16, 0x02, 0xcc},
+       {0xb3, 0x17, 0x7f, 0xcc},
+       {0xb3, 0x35, 0xdd, 0xcc},
+       {0xb3, 0x34, 0x02, 0xcc},
+       {0xb3, 0x00, 0x25, 0xcc},
+       {0xbc, 0x00, 0x71, 0xcc},
+       {0xb8, 0x00, 0x13, 0xcc},
+       {0xb8, 0x27, 0x20, 0xcc},
+       {0xb8, 0x2c, 0x50, 0xcc},
+       {0xb8, 0x2d, 0xf8, 0xcc},
+       {0xb8, 0x2e, 0xf8, 0xcc},
+       {0xb8, 0x2f, 0xf8, 0xcc},
+       {0xb8, 0x30, 0x50, 0xcc},
+       {0xb8, 0x31, 0xf8, 0xcc},
+       {0xb8, 0x32, 0xf8, 0xcc},
+       {0xb8, 0x33, 0xf8, 0xcc},
+       {0xb8, 0x34, 0x50, 0xcc},
+       {0xb8, 0x35, 0x00, 0xcc},
+       {0xb8, 0x36, 0x00, 0xcc},
+       {0xb8, 0x37, 0x00, 0xcc},
+       {0xb8, 0x01, 0x79, 0xcc},
+       {0xb8, 0x08, 0xe0, 0xcc},
+       {0xb3, 0x01, 0x41, 0xcc},
+       {0xb8, 0x01, 0x79, 0xcc},
+       {0xb8, 0x14, 0x18, 0xcc},
+       {0xb8, 0xb2, 0x0a, 0xcc},
+       {0xb8, 0xb4, 0x0a, 0xcc},
+       {0xb8, 0xb5, 0x0a, 0xcc},
+       {0xb8, 0xfe, 0x00, 0xcc},
+       {0xb8, 0xff, 0x28, 0xcc},
+       {0xb9, 0x00, 0x28, 0xcc},
+       {0xb9, 0x01, 0x28, 0xcc},
+       {0xb9, 0x02, 0x28, 0xcc},
+       {0xb9, 0x03, 0x00, 0xcc},
+       {0xb9, 0x04, 0x00, 0xcc},
+       {0xb9, 0x05, 0x3c, 0xcc},
+       {0xb9, 0x06, 0x3c, 0xcc},
+       {0xb9, 0x07, 0x3c, 0xcc},
+       {0xb9, 0x08, 0x3c, 0xcc},
+       {0xb8, 0x8e, 0x00, 0xcc},
+       {0xb8, 0x8f, 0xff, 0xcc},
+       {0xb8, 0x81, 0x09, 0xcc},
+       {0x31, 0x00, 0x00, 0xbb},
+       {0x09, 0x01, 0xc7, 0xbb},
+       {0x34, 0x01, 0x00, 0xbb},
+       {0x2b, 0x00, 0x28, 0xbb},
+       {0x2c, 0x00, 0x30, 0xbb},
+       {0x2d, 0x00, 0x30, 0xbb},
+       {0x2e, 0x00, 0x28, 0xbb},
+       {0x62, 0x04, 0x11, 0xbb},
+       {0x03, 0x01, 0xe0, 0xbb},
+       {0x2c, 0x00, 0x2c, 0xbb},
+       {0x20, 0xd0, 0x00, 0xbb},
+       {0x01, 0x00, 0x08, 0xbb},
+       {0x06, 0x00, 0x10, 0xbb},
+       {0x05, 0x00, 0x20, 0xbb},
+       {0x20, 0x00, 0x00, 0xbb},
+       {0xb6, 0x00, 0x00, 0xcc},
+       {0xb6, 0x03, 0x02, 0xcc},
+       {0xb6, 0x02, 0x80, 0xcc},
+       {0xb6, 0x05, 0x01, 0xcc},
+       {0xb6, 0x04, 0xe0, 0xcc},
+       {0xb6, 0x12, 0x78, 0xcc},
+       {0xb6, 0x18, 0x02, 0xcc},
+       {0xb6, 0x17, 0x58, 0xcc},
+       {0xb6, 0x16, 0x00, 0xcc},
+       {0xb6, 0x22, 0x12, 0xcc},
+       {0xb6, 0x23, 0x0b, 0xcc},
+       {0xb3, 0x02, 0x02, 0xcc},
+       {0xbf, 0xc0, 0x39, 0xcc},
+       {0xbf, 0xc1, 0x04, 0xcc},
+       {0xbf, 0xcc, 0x10, 0xcc},
+       {0xb9, 0x12, 0x00, 0xcc},
+       {0xb9, 0x13, 0x0a, 0xcc},
+       {0xb9, 0x14, 0x0a, 0xcc},
+       {0xb9, 0x15, 0x0a, 0xcc},
+       {0xb9, 0x16, 0x0a, 0xcc},
+       {0xb9, 0x18, 0x00, 0xcc},
+       {0xb9, 0x19, 0x0f, 0xcc},
+       {0xb9, 0x1a, 0x0f, 0xcc},
+       {0xb9, 0x1b, 0x0f, 0xcc},
+       {0xb9, 0x1c, 0x0f, 0xcc},
+       {0xb8, 0x8e, 0x00, 0xcc},
+       {0xb8, 0x8f, 0xff, 0xcc},
+       {0xb6, 0x12, 0xf8, 0xcc},
+       {0xb8, 0x0c, 0x20, 0xcc},
+       {0xb8, 0x0d, 0x70, 0xcc},
+       {0xb6, 0x13, 0x13, 0xcc},
+       {0x35, 0x00, 0x60, 0xbb},
+       {0xb3, 0x5c, 0x01, 0xcc},
+       {}
+};
+static const __u8 mi0360_initQVGA_JPG[][4] = {
+       {0xb0, 0x03, 0x19, 0xcc},
+       {0xb0, 0x04, 0x02, 0xcc},
+       {0xb3, 0x00, 0x24, 0xcc},
+       {0xb3, 0x00, 0x25, 0xcc},
+       {0xb3, 0x08, 0x01, 0xcc},
+       {0xb3, 0x09, 0x0c, 0xcc},
+       {0xb3, 0x05, 0x01, 0xcc},
+       {0xb3, 0x06, 0x03, 0xcc},
+       {0xb3, 0x03, 0x0a, 0xcc},
+       {0xb3, 0x20, 0x00, 0xcc},
+       {0xb3, 0x21, 0x00, 0xcc},
+       {0xb3, 0x22, 0x01, 0xcc},
+       {0xb3, 0x23, 0xe0, 0xcc},
+       {0xb3, 0x04, 0x05, 0xcc},
+       {0xb3, 0x14, 0x00, 0xcc},
+       {0xb3, 0x15, 0x00, 0xcc},
+       {0xb3, 0x16, 0x02, 0xcc},
+       {0xb3, 0x17, 0x7f, 0xcc},
+       {0xb3, 0x35, 0xdd, 0xcc},
+       {0xb3, 0x34, 0x02, 0xcc},
+       {0xb3, 0x00, 0x25, 0xcc},
+       {0xbc, 0x00, 0xd1, 0xcc},
+       {0xb8, 0x00, 0x13, 0xcc},
+       {0xb8, 0x27, 0x20, 0xcc},
+       {0xb8, 0x2c, 0x50, 0xcc},
+       {0xb8, 0x2d, 0xf8, 0xcc},
+       {0xb8, 0x2e, 0xf8, 0xcc},
+       {0xb8, 0x2f, 0xf8, 0xcc},
+       {0xb8, 0x30, 0x50, 0xcc},
+       {0xb8, 0x31, 0xf8, 0xcc},
+       {0xb8, 0x32, 0xf8, 0xcc},
+       {0xb8, 0x33, 0xf8, 0xcc},
+       {0xb8, 0x34, 0x50, 0xcc},
+       {0xb8, 0x35, 0x00, 0xcc},
+       {0xb8, 0x36, 0x00, 0xcc},
+       {0xb8, 0x37, 0x00, 0xcc},
+       {0xb8, 0x01, 0x79, 0xcc},
+       {0xb8, 0x08, 0xe0, 0xcc},
+       {0xb3, 0x01, 0x41, 0xcc},
+       {0xb8, 0x01, 0x79, 0xcc},
+       {0xb8, 0x14, 0x18, 0xcc},
+       {0xb8, 0xb2, 0x0a, 0xcc},
+       {0xb8, 0xb4, 0x0a, 0xcc},
+       {0xb8, 0xb5, 0x0a, 0xcc},
+       {0xb8, 0xfe, 0x00, 0xcc},
+       {0xb8, 0xff, 0x28, 0xcc},
+       {0xb9, 0x00, 0x28, 0xcc},
+       {0xb9, 0x01, 0x28, 0xcc},
+       {0xb9, 0x02, 0x28, 0xcc},
+       {0xb9, 0x03, 0x00, 0xcc},
+       {0xb9, 0x04, 0x00, 0xcc},
+       {0xb9, 0x05, 0x3c, 0xcc},
+       {0xb9, 0x06, 0x3c, 0xcc},
+       {0xb9, 0x07, 0x3c, 0xcc},
+       {0xb9, 0x08, 0x3c, 0xcc},
+       {0xb8, 0x8e, 0x00, 0xcc},
+       {0xb8, 0x8f, 0xff, 0xcc},
+       {0xb8, 0x81, 0x09, 0xcc},
+       {0x31, 0x00, 0x00, 0xbb},
+       {0x09, 0x01, 0xc7, 0xbb},
+       {0x34, 0x01, 0x00, 0xbb},
+       {0x2b, 0x00, 0x28, 0xbb},
+       {0x2c, 0x00, 0x30, 0xbb},
+       {0x2d, 0x00, 0x30, 0xbb},
+       {0x2e, 0x00, 0x28, 0xbb},
+       {0x62, 0x04, 0x11, 0xbb},
+       {0x03, 0x01, 0xe0, 0xbb},
+       {0x2c, 0x00, 0x2c, 0xbb},
+       {0x20, 0xd0, 0x00, 0xbb},
+       {0x01, 0x00, 0x08, 0xbb},
+       {0x06, 0x00, 0x10, 0xbb},
+       {0x05, 0x00, 0x20, 0xbb},
+       {0x20, 0x00, 0x00, 0xbb},
+       {0xb6, 0x00, 0x00, 0xcc},
+       {0xb6, 0x03, 0x01, 0xcc},
+       {0xb6, 0x02, 0x40, 0xcc},
+       {0xb6, 0x05, 0x00, 0xcc},
+       {0xb6, 0x04, 0xf0, 0xcc},
+       {0xb6, 0x12, 0x78, 0xcc},
+       {0xb6, 0x18, 0x00, 0xcc},
+       {0xb6, 0x17, 0x96, 0xcc},
+       {0xb6, 0x16, 0x00, 0xcc},
+       {0xb6, 0x22, 0x12, 0xcc},
+       {0xb6, 0x23, 0x0b, 0xcc},
+       {0xb3, 0x02, 0x02, 0xcc},
+       {0xbf, 0xc0, 0x39, 0xcc},
+       {0xbf, 0xc1, 0x04, 0xcc},
+       {0xbf, 0xcc, 0x10, 0xcc},
+       {0xb9, 0x12, 0x00, 0xcc},
+       {0xb9, 0x13, 0x0a, 0xcc},
+       {0xb9, 0x14, 0x0a, 0xcc},
+       {0xb9, 0x15, 0x0a, 0xcc},
+       {0xb9, 0x16, 0x0a, 0xcc},
+       {0xb9, 0x18, 0x00, 0xcc},
+       {0xb9, 0x19, 0x0f, 0xcc},
+       {0xb9, 0x1a, 0x0f, 0xcc},
+       {0xb9, 0x1b, 0x0f, 0xcc},
+       {0xb9, 0x1c, 0x0f, 0xcc},
+       {0xb8, 0x8e, 0x00, 0xcc},
+       {0xb8, 0x8f, 0xff, 0xcc},
+       {0xb6, 0x12, 0xf8, 0xcc},
+       {0xb6, 0x13, 0x13, 0xcc},
+       {0xbc, 0x02, 0x18, 0xcc},
+       {0xbc, 0x03, 0x50, 0xcc},
+       {0xbc, 0x04, 0x18, 0xcc},
+       {0xbc, 0x05, 0x00, 0xcc},
+       {0xbc, 0x06, 0x00, 0xcc},
+       {0xbc, 0x08, 0x30, 0xcc},
+       {0xbc, 0x09, 0x40, 0xcc},
+       {0xbc, 0x0a, 0x10, 0xcc},
+       {0xb8, 0x0c, 0x20, 0xcc},
+       {0xb8, 0x0d, 0x70, 0xcc},
+       {0xbc, 0x0b, 0x00, 0xcc},
+       {0xbc, 0x0c, 0x00, 0xcc},
+       {0x35, 0x00, 0xef, 0xbb},
+       {0xb3, 0x5c, 0x01, 0xcc},
+       {}
+};
+
 static const __u8 mi1310_socinitVGA_JPG[][4] = {
        {0xb0, 0x03, 0x19, 0xcc},
        {0xb0, 0x04, 0x02, 0xcc},
@@ -1203,7 +1437,6 @@ static const __u8 ov7670_initQVGA_JPG[][4] = {
        {0x00, 0x77, 0x05, 0xaa },
        {},
 };
-
 struct sensor_info {
        int sensorId;
        __u8 I2cAdd;
@@ -1222,6 +1455,8 @@ static const struct sensor_info sensor_info_data[] = {
        {SENSOR_MI1320,     0x80 | 0xc8, 0x00, 0x148c, 0x64, 0x65, 0x01},
        {SENSOR_OV7670,     0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05},
        {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01},
+/* (tested in vc032x_probe_sensor) */
+/*     {SENSOR_MI0360,     0x80 | 0x5d, 0x00, 0x4382, 0x24, 0x25, 0x01}, */
 };
 
 /* read 'len' bytes in gspca_dev->usb_buf */
@@ -1283,7 +1518,7 @@ static void read_sensor_register(struct gspca_dev *gspca_dev,
        mdata = gspca_dev->usb_buf[0];
        reg_r(gspca_dev, 0xa1, 0xb33c, 1);
        ldata = gspca_dev->usb_buf[0];
-       PDEBUG(D_PROBE, "Read Sensor h (0x%02X) m (0x%02X) l (0x%02X)",
+       PDEBUG(D_PROBE, "Read Sensor %02x %02x%02x",
                hdata, mdata, ldata);
        reg_r(gspca_dev, 0xa1, 0xb334, 1);
        if (gspca_dev->usb_buf[0] == 0x02)
@@ -1300,7 +1535,7 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
        const struct sensor_info *ptsensor_info;
 
        reg_r(gspca_dev, 0xa1, 0xbfcf, 1);
-       PDEBUG(D_PROBE, "check sensor header %d", gspca_dev->usb_buf[0]);
+       PDEBUG(D_PROBE, "check sensor header %02x", gspca_dev->usb_buf[0]);
        for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) {
                ptsensor_info = &sensor_info_data[i];
                reg_w(dev, 0xa0, 0x02, 0xb334);
@@ -1309,16 +1544,15 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev)
                reg_w(dev, 0xa0, 0x01, 0xb308);
                reg_w(dev, 0xa0, 0x0c, 0xb309);
                reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335);
-/*             PDEBUG(D_PROBE,
-                       "check sensor VC032X -> %d Add -> ox%02X!",
-                       i, ptsensor_info->I2cAdd); */
                reg_w(dev, 0xa0, ptsensor_info->op, 0xb301);
                read_sensor_register(gspca_dev, ptsensor_info->IdAdd, &value);
-               if (value == ptsensor_info->VpId) {
-/*                     PDEBUG(D_PROBE, "find sensor VC032X -> ox%04X!",
-                               ptsensor_info->VpId); */
+               if (value == ptsensor_info->VpId)
+                       return ptsensor_info->sensorId;
+
+               /* special case for MI0360 */
+               if (ptsensor_info->sensorId == SENSOR_MI1310_SOC
+                   && value == 0x4382)
                        return ptsensor_info->sensorId;
-               }
        }
        return -1;
 }
@@ -1420,13 +1654,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
        cam = &gspca_dev->cam;
        cam->epaddr = 0x02;
        sd->bridge = id->driver_info;
-       if (sd->bridge == BRIDGE_VC0321) {
-               cam->cam_mode = vc0321_mode;
-               cam->nmodes = ARRAY_SIZE(vc0321_mode);
-       } else {
-               cam->cam_mode = vc0323_mode;
-               cam->nmodes = ARRAY_SIZE(vc0323_mode);
-       }
 
        vc0321_reset(gspca_dev);
        sensor = vc032x_probe_sensor(gspca_dev);
@@ -1436,29 +1663,36 @@ static int sd_config(struct gspca_dev *gspca_dev,
                return -EINVAL;
        case SENSOR_HV7131R:
                PDEBUG(D_PROBE, "Find Sensor HV7131R");
-               sd->sensor = SENSOR_HV7131R;
+               break;
+       case SENSOR_MI0360:
+               PDEBUG(D_PROBE, "Find Sensor MI0360");
+               sd->bridge = BRIDGE_VC0323;
                break;
        case SENSOR_MI1310_SOC:
                PDEBUG(D_PROBE, "Find Sensor MI1310_SOC");
-               sd->sensor = SENSOR_MI1310_SOC;
                break;
        case SENSOR_MI1320:
                PDEBUG(D_PROBE, "Find Sensor MI1320");
-               sd->sensor = SENSOR_MI1320;
                break;
        case SENSOR_OV7660:
                PDEBUG(D_PROBE, "Find Sensor OV7660");
-               sd->sensor = SENSOR_OV7660;
                break;
        case SENSOR_OV7670:
                PDEBUG(D_PROBE, "Find Sensor OV7670");
-               sd->sensor = SENSOR_OV7670;
                break;
        case SENSOR_PO3130NC:
                PDEBUG(D_PROBE, "Find Sensor PO3130NC");
-               sd->sensor = SENSOR_PO3130NC;
                break;
        }
+       sd->sensor = sensor;
+
+       if (sd->bridge == BRIDGE_VC0321) {
+               cam->cam_mode = vc0321_mode;
+               cam->nmodes = ARRAY_SIZE(vc0321_mode);
+       } else {
+               cam->cam_mode = vc0323_mode;
+               cam->nmodes = ARRAY_SIZE(vc0323_mode);
+       }
 
        sd->qindex = 7;
        sd->autogain = AUTOGAIN_DEF;
@@ -1551,6 +1785,17 @@ static int sd_start(struct gspca_dev *gspca_dev)
                        usb_exchange(gspca_dev, ov7670_initVGA_JPG);
                }
                break;
+       case SENSOR_MI0360:
+               GammaT = mi1320_gamma;
+               MatrixT = mi0360_matrix;
+               if (mode) {
+                       /* 320x240 */
+                       usb_exchange(gspca_dev, mi0360_initQVGA_JPG);
+               } else {
+                       /* 640x480 */
+                       usb_exchange(gspca_dev, mi0360_initVGA_JPG);
+               }
+               break;
        case SENSOR_MI1310_SOC:
                if (mode) {
                        /* 320x240 */