V4L/DVB (13422): gspca - ov534: ov772x changes from Richard Kaswy.
[safe/jmp/linux-2.6] / drivers / media / video / gspca / pac207.c
index a15bcca..57e13e2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Pixart PAC207BCA library
  *
- * Copyright (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl>
+ * Copyright (C) 2008 Hans de Goede <hdgoede@redhat.com>
  * Copyright (C) 2005 Thomas Kaiser thomas@kaiser-linux.li
  * Copyleft (C) 2005 Michel Xhaard mxhaard@magic.fr
  *
@@ -27,7 +27,7 @@
 
 #include "gspca.h"
 
-MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
+MODULE_AUTHOR("Hans de Goede <hdgoede@redhat.com>");
 MODULE_DESCRIPTION("Pixart PAC207");
 MODULE_LICENSE("GPL");
 
@@ -35,33 +35,19 @@ MODULE_LICENSE("GPL");
 
 #define PAC207_BRIGHTNESS_MIN          0
 #define PAC207_BRIGHTNESS_MAX          255
-#define PAC207_BRIGHTNESS_DEFAULT      4 /* power on default: 4 */
-
-/* An exposure value of 4 also works (3 does not) but then we need to lower
-   the compression balance setting when in 352x288 mode, otherwise the usb
-   bandwidth is not enough and packets get dropped resulting in corrupt
-   frames. The problem with this is that when the compression balance gets
-   lowered below 0x80, the pac207 starts using a different compression
-   algorithm for some lines, these lines get prefixed with a 0x2dd2 prefix
-   and currently we do not know how to decompress these lines, so for now
-   we use a minimum exposure value of 5 */
-#define PAC207_EXPOSURE_MIN            5
+#define PAC207_BRIGHTNESS_DEFAULT      46
+
+#define PAC207_EXPOSURE_MIN            3
 #define PAC207_EXPOSURE_MAX            26
-#define PAC207_EXPOSURE_DEFAULT                5 /* power on default: 3 ?? */
-#define PAC207_EXPOSURE_KNEE           11 /* 4 = 30 fps, 11 = 8, 15 = 6 */
+#define PAC207_EXPOSURE_DEFAULT                5 /* power on default: 3 */
+#define PAC207_EXPOSURE_KNEE           8 /* 4 = 30 fps, 11 = 8, 15 = 6 */
 
 #define PAC207_GAIN_MIN                        0
 #define PAC207_GAIN_MAX                        31
 #define PAC207_GAIN_DEFAULT            9 /* power on default: 9 */
-#define PAC207_GAIN_KNEE               20
+#define PAC207_GAIN_KNEE               31
 
 #define PAC207_AUTOGAIN_DEADZONE       30
-/* We calculating the autogain at the end of the transfer of a frame, at this
-   moment a frame with the old settings is being transmitted, and a frame is
-   being captured with the old settings. So if we adjust the autogain we must
-   ignore atleast the 2 next frames for the new settings to come into effect
-   before doing any other adjustments */
-#define PAC207_AUTOGAIN_IGNORE_FRAMES  3
 
 /* specific webcam descriptor */
 struct sd {
@@ -155,7 +141,7 @@ static struct ctrl sd_ctrls[] = {
        },
 };
 
-static struct v4l2_pix_format sif_mode[] = {
+static const struct v4l2_pix_format sif_mode[] = {
        {176, 144, V4L2_PIX_FMT_PAC207, V4L2_FIELD_NONE,
                .bytesperline = 176,
                .sizeimage = (176 + 2) * 144,
@@ -172,16 +158,12 @@ static struct v4l2_pix_format sif_mode[] = {
 };
 
 static const __u8 pac207_sensor_init[][8] = {
-       {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0xf0},
-       {0x00, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30},
+       {0x10, 0x12, 0x0d, 0x12, 0x0c, 0x01, 0x29, 0x84},
+       {0x49, 0x64, 0x64, 0x64, 0x04, 0x10, 0xf0, 0x30},
        {0x00, 0x00, 0x00, 0x70, 0xa0, 0xf8, 0x00, 0x00},
-       {0x00, 0x00, 0x32, 0x00, 0x96, 0x00, 0xa2, 0x02},
        {0x32, 0x00, 0x96, 0x00, 0xA2, 0x02, 0xaf, 0x00},
 };
 
-                       /* 48 reg_72 Rate Control end BalSize_4a =0x36 */
-static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 };
-
 static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
        const u8 *buffer, u16 length)
 {
@@ -262,7 +244,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
                " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
 
        cam = &gspca_dev->cam;
-       cam->epaddr = 0x05;
        cam->cam_mode = sif_mode;
        cam->nmodes = ARRAY_SIZE(sif_mode);
        sd->brightness = PAC207_BRIGHTNESS_DEFAULT;
@@ -281,13 +262,12 @@ static int sd_init(struct gspca_dev *gspca_dev)
                                 * Bit_1=LED,
                                 * Bit_2=Compression test mode enable */
        pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
-       pac207_write_reg(gspca_dev, 0x11, 0x30); /* Analog Bias */
 
        return 0;
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        __u8 mode;
@@ -296,15 +276,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
        pac207_write_regs(gspca_dev, 0x0002, pac207_sensor_init[0], 8);
        pac207_write_regs(gspca_dev, 0x000a, pac207_sensor_init[1], 8);
        pac207_write_regs(gspca_dev, 0x0012, pac207_sensor_init[2], 8);
-       pac207_write_regs(gspca_dev, 0x0040, pac207_sensor_init[3], 8);
-       pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[4], 8);
-       pac207_write_regs(gspca_dev, 0x0048, PacReg72, 4);
+       pac207_write_regs(gspca_dev, 0x0042, pac207_sensor_init[3], 8);
 
        /* Compression Balance */
        if (gspca_dev->width == 176)
                pac207_write_reg(gspca_dev, 0x4a, 0xff);
        else
-               pac207_write_reg(gspca_dev, 0x4a, 0x88);
+               pac207_write_reg(gspca_dev, 0x4a, 0x30);
        pac207_write_reg(gspca_dev, 0x4b, 0x00); /* Sram test value */
        pac207_write_reg(gspca_dev, 0x08, sd->brightness);
 
@@ -329,6 +307,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        sd->sof_read = 0;
        sd->autogain_ignore_frames = 0;
        atomic_set(&sd->avg_lum, -1);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -338,6 +317,9 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
 }
 
+/* Include pac common sof detection functions */
+#include "pac_common.h"
+
 static void pac207_do_auto_gain(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
@@ -349,14 +331,11 @@ static void pac207_do_auto_gain(struct gspca_dev *gspca_dev)
        if (sd->autogain_ignore_frames > 0)
                sd->autogain_ignore_frames--;
        else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
-                       100 + sd->brightness / 2, PAC207_AUTOGAIN_DEADZONE,
+                       100, PAC207_AUTOGAIN_DEADZONE,
                        PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE))
-               sd->autogain_ignore_frames = PAC207_AUTOGAIN_IGNORE_FRAMES;
+               sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
 }
 
-/* Include pac common sof detection functions */
-#include "pac_common.h"
-
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
                        struct gspca_frame *frame,
                        __u8 *data,
@@ -365,7 +344,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
        struct sd *sd = (struct sd *) gspca_dev;
        unsigned char *sof;
 
-       sof = pac_find_sof(gspca_dev, data, len);
+       sof = pac_find_sof(&sd->sof_read, data, len);
        if (sof) {
                int n;
 
@@ -500,7 +479,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
                sd->gain = PAC207_GAIN_DEFAULT;
                if (gspca_dev->streaming) {
                        sd->autogain_ignore_frames =
-                               PAC207_AUTOGAIN_IGNORE_FRAMES;
+                               PAC_AUTOGAIN_IGNORE_FRAMES;
                        setexposure(gspca_dev);
                        setgain(gspca_dev);
                }
@@ -534,12 +513,16 @@ static const struct sd_desc sd_desc = {
 static const __devinitdata struct usb_device_id device_table[] = {
        {USB_DEVICE(0x041e, 0x4028)},
        {USB_DEVICE(0x093a, 0x2460)},
+       {USB_DEVICE(0x093a, 0x2461)},
        {USB_DEVICE(0x093a, 0x2463)},
        {USB_DEVICE(0x093a, 0x2464)},
        {USB_DEVICE(0x093a, 0x2468)},
        {USB_DEVICE(0x093a, 0x2470)},
        {USB_DEVICE(0x093a, 0x2471)},
        {USB_DEVICE(0x093a, 0x2472)},
+       {USB_DEVICE(0x093a, 0x2474)},
+       {USB_DEVICE(0x093a, 0x2476)},
+       {USB_DEVICE(0x145f, 0x013a)},
        {USB_DEVICE(0x2001, 0xf115)},
        {}
 };
@@ -567,8 +550,10 @@ static struct usb_driver sd_driver = {
 /* -- module insert / remove -- */
 static int __init sd_mod_init(void)
 {
-       if (usb_register(&sd_driver) < 0)
-               return -1;
+       int ret;
+       ret = usb_register(&sd_driver);
+       if (ret < 0)
+               return ret;
        PDEBUG(D_PROBE, "registered");
        return 0;
 }