V4L/DVB (9553): gspca: Webcam 145f:013a added in pac207.
[linux-2.6.git] / drivers / media / video / gspca / pac207.c
index 5d68d3f..39473e6 100644 (file)
@@ -27,9 +27,6 @@
 
 #include "gspca.h"
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 1, 5)
-static const char version[] = "2.1.5";
-
 MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
 MODULE_DESCRIPTION("Pixart PAC207");
 MODULE_LICENSE("GPL");
@@ -59,12 +56,6 @@ MODULE_LICENSE("GPL");
 #define PAC207_GAIN_KNEE               20
 
 #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 {
@@ -134,7 +125,8 @@ static struct ctrl sd_ctrls[] = {
                .minimum = 0,
                .maximum = 1,
                .step   = 1,
-               .default_value = 1,
+#define AUTOGAIN_DEF 1
+               .default_value = AUTOGAIN_DEF,
                .flags = 0,
            },
            .set = sd_setautogain,
@@ -184,21 +176,18 @@ static const __u8 pac207_sensor_init[][8] = {
                        /* 48 reg_72 Rate Control end BalSize_4a =0x36 */
 static const __u8 PacReg72[] = { 0x00, 0x00, 0x36, 0x00 };
 
-static const unsigned char pac207_sof_marker[5] =
-               { 0xff, 0xff, 0x00, 0xff, 0x96 };
-
-int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
+static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
        const u8 *buffer, u16 length)
 {
        struct usb_device *udev = gspca_dev->dev;
        int err;
-       u8 kbuf[8];
 
-       memcpy(kbuf, buffer, length);
+       memcpy(gspca_dev->usb_buf, buffer, length);
 
        err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x01,
                        USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
-                       0x00, index, kbuf, length, PAC207_CTRL_TIMEOUT);
+                       0x00, index,
+                       gspca_dev->usb_buf, length, PAC207_CTRL_TIMEOUT);
        if (err < 0)
                PDEBUG(D_ERR,
                        "Failed to write registers to index 0x%04X, error %d)",
@@ -208,7 +197,7 @@ int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
 }
 
 
-int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
+static int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
 {
        struct usb_device *udev = gspca_dev->dev;
        int err;
@@ -223,16 +212,15 @@ int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
        return err;
 }
 
-
-int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
+static int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
 {
        struct usb_device *udev = gspca_dev->dev;
-       u8 buff;
        int res;
 
        res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x00,
                        USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
-                       0x00, index, &buff, 1, PAC207_CTRL_TIMEOUT);
+                       0x00, index,
+                       gspca_dev->usb_buf, 1, PAC207_CTRL_TIMEOUT);
        if (res < 0) {
                PDEBUG(D_ERR,
                        "Failed to read a register (index 0x%04X, error %d)",
@@ -240,10 +228,9 @@ int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
                return res;
        }
 
-       return buff;
+       return gspca_dev->usb_buf[0];
 }
 
-
 /* this function is called at probe time */
 static int sd_config(struct gspca_dev *gspca_dev,
                        const struct usb_device_id *id)
@@ -264,40 +251,37 @@ static int sd_config(struct gspca_dev *gspca_dev,
                return -ENODEV;
        }
 
-       pac207_write_reg(gspca_dev, 0x41, 0x00);
-                               /* Bit_0=Image Format,
-                                * 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 */
-
        PDEBUG(D_PROBE,
                "Pixart PAC207BCA Image Processor and Control Chip detected"
                " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct);
 
        cam = &gspca_dev->cam;
-       cam->dev_name = (char *) id->driver_info;
        cam->epaddr = 0x05;
        cam->cam_mode = sif_mode;
        cam->nmodes = ARRAY_SIZE(sif_mode);
        sd->brightness = PAC207_BRIGHTNESS_DEFAULT;
        sd->exposure = PAC207_EXPOSURE_DEFAULT;
        sd->gain = PAC207_GAIN_DEFAULT;
+       sd->autogain = AUTOGAIN_DEF;
 
        return 0;
 }
 
-/* this function is called at open time */
-static int sd_open(struct gspca_dev *gspca_dev)
+/* this function is called at probe and resume time */
+static int sd_init(struct gspca_dev *gspca_dev)
 {
-       struct sd *sd = (struct sd *) gspca_dev;
+       pac207_write_reg(gspca_dev, 0x41, 0x00);
+                               /* Bit_0=Image Format,
+                                * 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 */
 
-       sd->autogain = 1;
        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;
@@ -339,6 +323,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)
@@ -348,14 +333,8 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        pac207_write_reg(gspca_dev, 0x0f, 0x00); /* Power Control */
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-}
-
-/* this function is called at close time */
-static void sd_close(struct gspca_dev *gspca_dev)
-{
-}
+/* Include pac common sof detection functions */
+#include "pac_common.h"
 
 static void pac207_do_auto_gain(struct gspca_dev *gspca_dev)
 {
@@ -370,33 +349,7 @@ static void pac207_do_auto_gain(struct gspca_dev *gspca_dev)
        else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum,
                        100 + sd->brightness / 2, PAC207_AUTOGAIN_DEADZONE,
                        PAC207_GAIN_KNEE, PAC207_EXPOSURE_KNEE))
-               sd->autogain_ignore_frames = PAC207_AUTOGAIN_IGNORE_FRAMES;
-}
-
-static unsigned char *pac207_find_sof(struct gspca_dev *gspca_dev,
-                                       unsigned char *m, int len)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-       int i;
-
-       /* Search for the SOF marker (fixed part) in the header */
-       for (i = 0; i < len; i++) {
-               if (m[i] == pac207_sof_marker[sd->sof_read]) {
-                       sd->sof_read++;
-                       if (sd->sof_read == sizeof(pac207_sof_marker)) {
-                               PDEBUG(D_STREAM,
-                                       "SOF found, bytes to analyze: %u."
-                                       " Frame starts at byte #%u",
-                                       len, i + 1);
-                               sd->sof_read = 0;
-                               return m + i + 1;
-                       }
-               } else {
-                       sd->sof_read = 0;
-               }
-       }
-
-       return NULL;
+               sd->autogain_ignore_frames = PAC_AUTOGAIN_IGNORE_FRAMES;
 }
 
 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
@@ -407,14 +360,14 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
        struct sd *sd = (struct sd *) gspca_dev;
        unsigned char *sof;
 
-       sof = pac207_find_sof(gspca_dev, data, len);
+       sof = pac_find_sof(gspca_dev, data, len);
        if (sof) {
                int n;
 
                /* finish decoding current frame */
                n = sof - data;
-               if (n > sizeof pac207_sof_marker)
-                       n -= sizeof pac207_sof_marker;
+               if (n > sizeof pac_sof_marker)
+                       n -= sizeof pac_sof_marker;
                else
                        n = 0;
                frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
@@ -542,7 +495,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);
                }
@@ -565,27 +518,26 @@ static const struct sd_desc sd_desc = {
        .ctrls = sd_ctrls,
        .nctrls = ARRAY_SIZE(sd_ctrls),
        .config = sd_config,
-       .open = sd_open,
+       .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
-       .close = sd_close,
        .dq_callback = pac207_do_auto_gain,
        .pkt_scan = sd_pkt_scan,
 };
 
 /* -- module initialisation -- */
-#define DVNM(name) .driver_info = (kernel_ulong_t) name
 static const __devinitdata struct usb_device_id device_table[] = {
-       {USB_DEVICE(0x041e, 0x4028), DVNM("Creative Webcam Vista Plus")},
-       {USB_DEVICE(0x093a, 0x2460), DVNM("Q-Tec Webcam 100")},
-       {USB_DEVICE(0x093a, 0x2463), DVNM("Philips spc200nc pac207")},
-       {USB_DEVICE(0x093a, 0x2464), DVNM("Labtec Webcam 1200")},
-       {USB_DEVICE(0x093a, 0x2468), DVNM("PAC207")},
-       {USB_DEVICE(0x093a, 0x2470), DVNM("Genius GF112")},
-       {USB_DEVICE(0x093a, 0x2471), DVNM("Genius VideoCam GE111")},
-       {USB_DEVICE(0x093a, 0x2472), DVNM("Genius VideoCam GE110")},
-       {USB_DEVICE(0x2001, 0xf115), DVNM("D-Link DSB-C120")},
+       {USB_DEVICE(0x041e, 0x4028)},
+       {USB_DEVICE(0x093a, 0x2460)},
+       {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, 0x2476)},
+       {USB_DEVICE(0x145f, 0x013a)},
+       {USB_DEVICE(0x2001, 0xf115)},
        {}
 };
 MODULE_DEVICE_TABLE(usb, device_table);
@@ -603,6 +555,10 @@ static struct usb_driver sd_driver = {
        .id_table = device_table,
        .probe = sd_probe,
        .disconnect = gspca_disconnect,
+#ifdef CONFIG_PM
+       .suspend = gspca_suspend,
+       .resume = gspca_resume,
+#endif
 };
 
 /* -- module insert / remove -- */
@@ -610,7 +566,7 @@ static int __init sd_mod_init(void)
 {
        if (usb_register(&sd_driver) < 0)
                return -1;
-       PDEBUG(D_PROBE, "v%s registered", version);
+       PDEBUG(D_PROBE, "registered");
        return 0;
 }
 static void __exit sd_mod_exit(void)