The patch number 14543 was added via Douglas Schilling Landgraf 
<[email protected]>
to http://linuxtv.org/hg/v4l-dvb master development tree.

Kernel patches in this development tree may be modified to be backward
compatible with older kernels. Compatibility modifications will be
removed before inclusion into the mainstream Kernel

If anyone has any objections, please let us know by sending a message to:
        Linux Media Mailing List <[email protected]>

------

From: Hans Verkuil  <[email protected]>
w9966: reorganize the order of functions


Get rid of completely unnecessary function prototypes.

Priority: normal

Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
Signed-off-by: Douglas Schilling Landgraf <[email protected]>


---

 linux/drivers/media/video/w9966.c |  629 ++++++++++++++----------------
 1 file changed, 296 insertions(+), 333 deletions(-)

diff -r 7d8d26182436 -r fc4e65dea1af linux/drivers/media/video/w9966.c
--- a/linux/drivers/media/video/w9966.c Sun Apr 04 20:23:52 2010 -0400
+++ b/linux/drivers/media/video/w9966.c Sun Apr 04 20:50:41 2010 -0400
@@ -144,77 +144,9 @@
 static int video_nr = -1;
 module_param(video_nr, int, 0);
 
-/*
- *     Private data
- */
-
 static struct w9966_dev w9966_cams[W9966_MAXCAMS];
 
 /*
- *     Private function declares
- */
-
-static inline void w9966_setState(struct w9966_dev *cam, int mask, int val);
-static inline int  w9966_getState(struct w9966_dev *cam, int mask, int val);
-static inline void w9966_pdev_claim(struct w9966_dev *vdev);
-static inline void w9966_pdev_release(struct w9966_dev *vdev);
-
-static int w9966_rReg(struct w9966_dev *cam, int reg);
-static int w9966_wReg(struct w9966_dev *cam, int reg, int data);
-#if 0 /* keep */
-static int w9966_rReg_i2c(struct w9966_dev *cam, int reg);
-#endif
-static int w9966_wReg_i2c(struct w9966_dev *cam, int reg, int data);
-static int w9966_findlen(int near, int size, int maxlen);
-static int w9966_calcscale(int size, int min, int max, int *beg, int *end, 
unsigned char *factor);
-static int w9966_setup(struct w9966_dev *cam, int x1, int y1, int x2, int y2, 
int w, int h);
-
-static int  w9966_init(struct w9966_dev *cam, struct parport* port);
-static void w9966_term(struct w9966_dev *cam);
-
-static inline void w9966_i2c_setsda(struct w9966_dev *cam, int state);
-static inline int  w9966_i2c_setscl(struct w9966_dev *cam, int state);
-static inline int  w9966_i2c_getsda(struct w9966_dev *cam);
-static inline int  w9966_i2c_getscl(struct w9966_dev *cam);
-static int w9966_i2c_wbyte(struct w9966_dev *cam, int data);
-#if 0 /* keep */
-static int w9966_i2c_rbyte(struct w9966_dev *cam);
-#endif
-
-static long w9966_v4l_ioctl(struct file *file,
-                          unsigned int cmd, unsigned long arg);
-static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
-                             size_t count, loff_t *ppos);
-
-static int w9966_exclusive_open(struct file *file)
-{
-       struct w9966_dev *cam = video_drvdata(file);
-
-       return test_and_set_bit(0, &cam->in_use) ? -EBUSY : 0;
-}
-
-static int w9966_exclusive_release(struct file *file)
-{
-       struct w9966_dev *cam = video_drvdata(file);
-
-       clear_bit(0, &cam->in_use);
-       return 0;
-}
-
-static const struct v4l2_file_operations w9966_fops = {
-       .owner          = THIS_MODULE,
-       .open           = w9966_exclusive_open,
-       .release        = w9966_exclusive_release,
-       .ioctl          = w9966_v4l_ioctl,
-       .read           = w9966_v4l_read,
-};
-static struct video_device w9966_template = {
-       .name           = W9966_DRIVERNAME,
-       .fops           = &w9966_fops,
-       .release        = video_device_release_empty,
-};
-
-/*
  *     Private function defines
  */
 
@@ -232,7 +164,7 @@
 }
 
 /* Claim parport for ourself */
-static inline void w9966_pdev_claim(struct w9966_dev *cam)
+static void w9966_pdev_claim(struct w9966_dev *cam)
 {
        if (w9966_getState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED))
                return;
@@ -241,7 +173,7 @@
 }
 
 /* Release parport for others to use */
-static inline void w9966_pdev_release(struct w9966_dev *cam)
+static void w9966_pdev_release(struct w9966_dev *cam)
 {
        if (w9966_getState(cam, W9966_STATE_CLAIMED, 0))
                return;
@@ -291,272 +223,13 @@
        return 0;
 }
 
-/* Initialize camera device. Setup all internal flags, set a
-   default video mode, setup ccd-chip, register v4l device etc..
-   Also used for 'probing' of hardware.
-   -1 on error */
-static int w9966_init(struct w9966_dev *cam, struct parport* port)
-{
-       if (cam->dev_state != 0)
-               return -1;
-
-       cam->pport = port;
-       cam->brightness = 128;
-       cam->contrast = 64;
-       cam->color = 64;
-       cam->hue = 0;
-
-/* Select requested transfer mode */
-       switch (parmode) {
-       default:        /* Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) */
-       case 0:
-               if (port->modes & PARPORT_MODE_ECP)
-                       cam->ppmode = IEEE1284_MODE_ECP;
-               else if (port->modes & PARPORT_MODE_EPP)
-                       cam->ppmode = IEEE1284_MODE_EPP;
-               else
-                       cam->ppmode = IEEE1284_MODE_ECP;
-               break;
-       case 1:         /* hw- or sw-ecp */
-               cam->ppmode = IEEE1284_MODE_ECP;
-               break;
-       case 2:         /* hw- or sw-epp */
-               cam->ppmode = IEEE1284_MODE_EPP;
-       break;
-       }
-
-/* Tell the parport driver that we exists */
-       cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, 
NULL);
-       if (cam->pdev == NULL) {
-               DPRINTF("parport_register_device() failed\n");
-               return -1;
-       }
-       w9966_setState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV);
-
-       w9966_pdev_claim(cam);
-
-/* Setup a default capture mode */
-       if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) {
-               DPRINTF("w9966_setup() failed.\n");
-               return -1;
-       }
-
-       w9966_pdev_release(cam);
-
-/* Fill in the video_device struct and register us to v4l */
-       memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device));
-       video_set_drvdata(&cam->vdev, cam);
-
-       if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
-               return -1;
-
-       w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV);
-
-       /* All ok */
-       printk(KERN_INFO "w9966cf: Found and initialized a webcam on %s.\n",
-               cam->pport->name);
-       return 0;
-}
-
-
-/* Terminate everything gracefully */
-static void w9966_term(struct w9966_dev *cam)
-{
-/* Unregister from v4l */
-       if (w9966_getState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) {
-               video_unregister_device(&cam->vdev);
-               w9966_setState(cam, W9966_STATE_VDEV, 0);
-       }
-
-/* Terminate from IEEE1284 mode and release pdev block */
-       if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
-               w9966_pdev_claim(cam);
-               parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT);
-               w9966_pdev_release(cam);
-       }
-
-/* Unregister from parport */
-       if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
-               parport_unregister_device(cam->pdev);
-               w9966_setState(cam, W9966_STATE_PDEV, 0);
-       }
-}
-
-
-/* Find a good length for capture window (used both for W and H)
-   A bit ugly but pretty functional. The capture length
-   have to match the downscale */
-static int w9966_findlen(int near, int size, int maxlen)
-{
-       int bestlen = size;
-       int besterr = abs(near - bestlen);
-       int len;
-
-       for (len = size + 1; len < maxlen; len++) {
-               int err;
-               if (((64 * size) % len) != 0)
-                       continue;
-
-               err = abs(near - len);
-
-               /* Only continue as long as we keep getting better values */
-               if (err > besterr)
-                       break;
-
-               besterr = err;
-               bestlen = len;
-       }
-
-       return bestlen;
-}
-
-/* Modify capture window (if necessary)
-   and calculate downscaling
-   Return -1 on error */
-static int w9966_calcscale(int size, int min, int max, int *beg, int *end, 
unsigned char *factor)
-{
-       int maxlen = max - min;
-       int len = *end - *beg + 1;
-       int newlen = w9966_findlen(len, size, maxlen);
-       int err = newlen - len;
-
-       /* Check for bad format */
-       if (newlen > maxlen || newlen < size)
-               return -1;
-
-       /* Set factor (6 bit fixed) */
-       *factor = (64 * size) / newlen;
-       if (*factor == 64)
-               *factor = 0x00; /* downscale is disabled */
-       else
-               *factor |= 0x80; /* set downscale-enable bit */
-
-       /* Modify old beginning and end */
-       *beg -= err / 2;
-       *end += err - (err / 2);
-
-       /* Move window if outside borders */
-       if (*beg < min) {
-               *end += min - *beg;
-               *beg += min - *beg;
-       }
-       if (*end > max) {
-               *beg -= *end - max;
-               *end -= *end - max;
-       }
-
-       return 0;
-}
-
-/* Setup the cameras capture window etc.
-   Expects a claimed pdev
-   return -1 on error */
-static int w9966_setup(struct w9966_dev *cam, int x1, int y1, int x2, int y2, 
int w, int h)
-{
-       unsigned int i;
-       unsigned int enh_s, enh_e;
-       unsigned char scale_x, scale_y;
-       unsigned char regs[0x1c];
-       unsigned char saa7111_regs[] = {
-               0x21, 0x00, 0xd8, 0x23, 0x00, 0x80, 0x80, 0x00,
-               0x88, 0x10, 0x80, 0x40, 0x40, 0x00, 0x01, 0x00,
-               0x48, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x71, 0xe7, 0x00, 0x00, 0xc0
-       };
-
-
-       if (w * h * 2 > W9966_SRAMSIZE) {
-               DPRINTF("capture window exceeds SRAM size!.\n");
-               w = 200; h = 160;       /* Pick default values */
-       }
-
-       w &= ~0x1;
-       if (w < 2)
-               w = 2;
-       if (h < 1)
-               h = 1;
-       if (w > W9966_WND_MAX_W)
-               w = W9966_WND_MAX_W;
-       if (h > W9966_WND_MAX_H)
-               h = W9966_WND_MAX_H;
-
-       cam->width = w;
-       cam->height = h;
-
-       enh_s = 0;
-       enh_e = w * h * 2;
-
-/* Modify capture window if necessary and calculate downscaling */
-       if (w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, 
&scale_x) != 0 ||
-           w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, 
&scale_y) != 0)
-               return -1;
-
-       DPRINTF("%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n",
-               w, h, x1, x2, y1, y2, scale_x & ~0x80, scale_y & ~0x80);
-
-/* Setup registers */
-       regs[0x00] = 0x00;                      /* Set normal operation */
-       regs[0x01] = 0x18;                      /* Capture mode */
-       regs[0x02] = scale_y;                   /* V-scaling */
-       regs[0x03] = scale_x;                   /* H-scaling */
-
-       /* Capture window */
-       regs[0x04] = (x1 & 0x0ff);              /* X-start (8 low bits) */
-       regs[0x05] = (x1 & 0x300)>>8;           /* X-start (2 high bits) */
-       regs[0x06] = (y1 & 0x0ff);              /* Y-start (8 low bits) */
-       regs[0x07] = (y1 & 0x300)>>8;           /* Y-start (2 high bits) */
-       regs[0x08] = (x2 & 0x0ff);              /* X-end (8 low bits) */
-       regs[0x09] = (x2 & 0x300)>>8;           /* X-end (2 high bits) */
-       regs[0x0a] = (y2 & 0x0ff);              /* Y-end (8 low bits) */
-
-       regs[0x0c] = W9966_SRAMID;              /* SRAM-banks (1x 128kb) */
-
-       /* Enhancement layer */
-       regs[0x0d] = (enh_s & 0x000ff);         /* Enh. start (0-7) */
-       regs[0x0e] = (enh_s & 0x0ff00) >> 8;    /* Enh. start (8-15) */
-       regs[0x0f] = (enh_s & 0x70000) >> 16;   /* Enh. start (16-17/18??) */
-       regs[0x10] = (enh_e & 0x000ff);         /* Enh. end (0-7) */
-       regs[0x11] = (enh_e & 0x0ff00) >> 8;    /* Enh. end (8-15) */
-       regs[0x12] = (enh_e & 0x70000) >> 16;   /* Enh. end (16-17/18??) */
-
-       /* Misc */
-       regs[0x13] = 0x40;                      /* VEE control (raw 4:2:2) */
-       regs[0x17] = 0x00;                      /* ??? */
-       regs[0x18] = cam->i2c_state = 0x00;     /* Serial bus */
-       regs[0x19] = 0xff;                      /* I/O port direction control */
-       regs[0x1a] = 0xff;                      /* I/O port data register */
-       regs[0x1b] = 0x10;                      /* ??? */
-
-       /* SAA7111 chip settings */
-       saa7111_regs[0x0a] = cam->brightness;
-       saa7111_regs[0x0b] = cam->contrast;
-       saa7111_regs[0x0c] = cam->color;
-       saa7111_regs[0x0d] = cam->hue;
-
-/* Reset (ECP-fifo & serial-bus) */
-       if (w9966_wReg(cam, 0x00, 0x03) == -1)
-               return -1;
-
-/* Write regs to w9966cf chip */
-       for (i = 0; i < 0x1c; i++)
-               if (w9966_wReg(cam, i, regs[i]) == -1)
-                       return -1;
-
-/* Write regs to saa7111 chip */
-       for (i = 0; i < 0x20; i++)
-               if (w9966_wReg_i2c(cam, i, saa7111_regs[i]) == -1)
-                       return -1;
-
-       return 0;
-}
-
 /*
  *     Ugly and primitive i2c protocol functions
  */
 
 /* Sets the data line on the i2c bus.
    Expects a claimed pdev. */
-static inline void w9966_i2c_setsda(struct w9966_dev *cam, int state)
+static void w9966_i2c_setsda(struct w9966_dev *cam, int state)
 {
        if (state)
                cam->i2c_state |= W9966_I2C_W_DATA;
@@ -569,7 +242,7 @@
 
 /* Get peripheral clock line
    Expects a claimed pdev. */
-static inline int w9966_i2c_getscl(struct w9966_dev *cam)
+static int w9966_i2c_getscl(struct w9966_dev *cam)
 {
        const unsigned char state = w9966_rReg(cam, 0x18);
        return ((state & W9966_I2C_R_CLOCK) > 0);
@@ -577,7 +250,7 @@
 
 /* Sets the clock line on the i2c bus.
    Expects a claimed pdev. -1 on error */
-static inline int w9966_i2c_setscl(struct w9966_dev *cam, int state)
+static int w9966_i2c_setscl(struct w9966_dev *cam, int state)
 {
        unsigned long timeout;
 
@@ -600,13 +273,15 @@
        return 0;
 }
 
+#if 0 /* keep */
 /* Get peripheral data line
    Expects a claimed pdev. */
-static inline int w9966_i2c_getsda(struct w9966_dev *cam)
+static int w9966_i2c_getsda(struct w9966_dev *cam)
 {
        const unsigned char state = w9966_rReg(cam, 0x18);
        return ((state & W9966_I2C_R_DATA) > 0);
 }
+#endif
 
 /* Write a byte with ack to the i2c bus.
    Expects a claimed pdev. -1 on error */
@@ -711,6 +386,173 @@
        return 0;
 }
 
+/* Find a good length for capture window (used both for W and H)
+   A bit ugly but pretty functional. The capture length
+   have to match the downscale */
+static int w9966_findlen(int near, int size, int maxlen)
+{
+       int bestlen = size;
+       int besterr = abs(near - bestlen);
+       int len;
+
+       for (len = size + 1; len < maxlen; len++) {
+               int err;
+               if (((64 * size) % len) != 0)
+                       continue;
+
+               err = abs(near - len);
+
+               /* Only continue as long as we keep getting better values */
+               if (err > besterr)
+                       break;
+
+               besterr = err;
+               bestlen = len;
+       }
+
+       return bestlen;
+}
+
+/* Modify capture window (if necessary)
+   and calculate downscaling
+   Return -1 on error */
+static int w9966_calcscale(int size, int min, int max, int *beg, int *end, 
unsigned char *factor)
+{
+       int maxlen = max - min;
+       int len = *end - *beg + 1;
+       int newlen = w9966_findlen(len, size, maxlen);
+       int err = newlen - len;
+
+       /* Check for bad format */
+       if (newlen > maxlen || newlen < size)
+               return -1;
+
+       /* Set factor (6 bit fixed) */
+       *factor = (64 * size) / newlen;
+       if (*factor == 64)
+               *factor = 0x00; /* downscale is disabled */
+       else
+               *factor |= 0x80; /* set downscale-enable bit */
+
+       /* Modify old beginning and end */
+       *beg -= err / 2;
+       *end += err - (err / 2);
+
+       /* Move window if outside borders */
+       if (*beg < min) {
+               *end += min - *beg;
+               *beg += min - *beg;
+       }
+       if (*end > max) {
+               *beg -= *end - max;
+               *end -= *end - max;
+       }
+
+       return 0;
+}
+
+/* Setup the cameras capture window etc.
+   Expects a claimed pdev
+   return -1 on error */
+static int w9966_setup(struct w9966_dev *cam, int x1, int y1, int x2, int y2, 
int w, int h)
+{
+       unsigned int i;
+       unsigned int enh_s, enh_e;
+       unsigned char scale_x, scale_y;
+       unsigned char regs[0x1c];
+       unsigned char saa7111_regs[] = {
+               0x21, 0x00, 0xd8, 0x23, 0x00, 0x80, 0x80, 0x00,
+               0x88, 0x10, 0x80, 0x40, 0x40, 0x00, 0x01, 0x00,
+               0x48, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0x00, 0x00, 0x00, 0x71, 0xe7, 0x00, 0x00, 0xc0
+       };
+
+
+       if (w * h * 2 > W9966_SRAMSIZE) {
+               DPRINTF("capture window exceeds SRAM size!.\n");
+               w = 200; h = 160;       /* Pick default values */
+       }
+
+       w &= ~0x1;
+       if (w < 2)
+               w = 2;
+       if (h < 1)
+               h = 1;
+       if (w > W9966_WND_MAX_W)
+               w = W9966_WND_MAX_W;
+       if (h > W9966_WND_MAX_H)
+               h = W9966_WND_MAX_H;
+
+       cam->width = w;
+       cam->height = h;
+
+       enh_s = 0;
+       enh_e = w * h * 2;
+
+/* Modify capture window if necessary and calculate downscaling */
+       if (w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, 
&scale_x) != 0 ||
+           w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, 
&scale_y) != 0)
+               return -1;
+
+       DPRINTF("%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n",
+               w, h, x1, x2, y1, y2, scale_x & ~0x80, scale_y & ~0x80);
+
+/* Setup registers */
+       regs[0x00] = 0x00;                      /* Set normal operation */
+       regs[0x01] = 0x18;                      /* Capture mode */
+       regs[0x02] = scale_y;                   /* V-scaling */
+       regs[0x03] = scale_x;                   /* H-scaling */
+
+       /* Capture window */
+       regs[0x04] = (x1 & 0x0ff);              /* X-start (8 low bits) */
+       regs[0x05] = (x1 & 0x300)>>8;           /* X-start (2 high bits) */
+       regs[0x06] = (y1 & 0x0ff);              /* Y-start (8 low bits) */
+       regs[0x07] = (y1 & 0x300)>>8;           /* Y-start (2 high bits) */
+       regs[0x08] = (x2 & 0x0ff);              /* X-end (8 low bits) */
+       regs[0x09] = (x2 & 0x300)>>8;           /* X-end (2 high bits) */
+       regs[0x0a] = (y2 & 0x0ff);              /* Y-end (8 low bits) */
+
+       regs[0x0c] = W9966_SRAMID;              /* SRAM-banks (1x 128kb) */
+
+       /* Enhancement layer */
+       regs[0x0d] = (enh_s & 0x000ff);         /* Enh. start (0-7) */
+       regs[0x0e] = (enh_s & 0x0ff00) >> 8;    /* Enh. start (8-15) */
+       regs[0x0f] = (enh_s & 0x70000) >> 16;   /* Enh. start (16-17/18??) */
+       regs[0x10] = (enh_e & 0x000ff);         /* Enh. end (0-7) */
+       regs[0x11] = (enh_e & 0x0ff00) >> 8;    /* Enh. end (8-15) */
+       regs[0x12] = (enh_e & 0x70000) >> 16;   /* Enh. end (16-17/18??) */
+
+       /* Misc */
+       regs[0x13] = 0x40;                      /* VEE control (raw 4:2:2) */
+       regs[0x17] = 0x00;                      /* ??? */
+       regs[0x18] = cam->i2c_state = 0x00;     /* Serial bus */
+       regs[0x19] = 0xff;                      /* I/O port direction control */
+       regs[0x1a] = 0xff;                      /* I/O port data register */
+       regs[0x1b] = 0x10;                      /* ??? */
+
+       /* SAA7111 chip settings */
+       saa7111_regs[0x0a] = cam->brightness;
+       saa7111_regs[0x0b] = cam->contrast;
+       saa7111_regs[0x0c] = cam->color;
+       saa7111_regs[0x0d] = cam->hue;
+
+/* Reset (ECP-fifo & serial-bus) */
+       if (w9966_wReg(cam, 0x00, 0x03) == -1)
+               return -1;
+
+/* Write regs to w9966cf chip */
+       for (i = 0; i < 0x1c; i++)
+               if (w9966_wReg(cam, i, regs[i]) == -1)
+                       return -1;
+
+/* Write regs to saa7111 chip */
+       for (i = 0; i < 0x20; i++)
+               if (w9966_wReg_i2c(cam, i, saa7111_regs[i]) == -1)
+                       return -1;
+
+       return 0;
+}
+
 /*
  *     Video4linux interfacing
  */
@@ -927,6 +769,127 @@
        return count;
 }
 
+static int w9966_exclusive_open(struct file *file)
+{
+       struct w9966_dev *cam = video_drvdata(file);
+
+       return test_and_set_bit(0, &cam->in_use) ? -EBUSY : 0;
+}
+
+static int w9966_exclusive_release(struct file *file)
+{
+       struct w9966_dev *cam = video_drvdata(file);
+
+       clear_bit(0, &cam->in_use);
+       return 0;
+}
+
+static const struct v4l2_file_operations w9966_fops = {
+       .owner          = THIS_MODULE,
+       .open           = w9966_exclusive_open,
+       .release        = w9966_exclusive_release,
+       .ioctl          = w9966_v4l_ioctl,
+       .read           = w9966_v4l_read,
+};
+
+static struct video_device w9966_template = {
+       .name           = W9966_DRIVERNAME,
+       .fops           = &w9966_fops,
+       .release        = video_device_release_empty,
+};
+
+
+/* Initialize camera device. Setup all internal flags, set a
+   default video mode, setup ccd-chip, register v4l device etc..
+   Also used for 'probing' of hardware.
+   -1 on error */
+static int w9966_init(struct w9966_dev *cam, struct parport* port)
+{
+       if (cam->dev_state != 0)
+               return -1;
+
+       cam->pport = port;
+       cam->brightness = 128;
+       cam->contrast = 64;
+       cam->color = 64;
+       cam->hue = 0;
+
+/* Select requested transfer mode */
+       switch (parmode) {
+       default:        /* Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) */
+       case 0:
+               if (port->modes & PARPORT_MODE_ECP)
+                       cam->ppmode = IEEE1284_MODE_ECP;
+               else if (port->modes & PARPORT_MODE_EPP)
+                       cam->ppmode = IEEE1284_MODE_EPP;
+               else
+                       cam->ppmode = IEEE1284_MODE_ECP;
+               break;
+       case 1:         /* hw- or sw-ecp */
+               cam->ppmode = IEEE1284_MODE_ECP;
+               break;
+       case 2:         /* hw- or sw-epp */
+               cam->ppmode = IEEE1284_MODE_EPP;
+       break;
+       }
+
+/* Tell the parport driver that we exists */
+       cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, 
NULL);
+       if (cam->pdev == NULL) {
+               DPRINTF("parport_register_device() failed\n");
+               return -1;
+       }
+       w9966_setState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV);
+
+       w9966_pdev_claim(cam);
+
+/* Setup a default capture mode */
+       if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) {
+               DPRINTF("w9966_setup() failed.\n");
+               return -1;
+       }
+
+       w9966_pdev_release(cam);
+
+/* Fill in the video_device struct and register us to v4l */
+       memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device));
+       video_set_drvdata(&cam->vdev, cam);
+
+       if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
+               return -1;
+
+       w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV);
+
+       /* All ok */
+       printk(KERN_INFO "w9966cf: Found and initialized a webcam on %s.\n",
+               cam->pport->name);
+       return 0;
+}
+
+
+/* Terminate everything gracefully */
+static void w9966_term(struct w9966_dev *cam)
+{
+/* Unregister from v4l */
+       if (w9966_getState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) {
+               video_unregister_device(&cam->vdev);
+               w9966_setState(cam, W9966_STATE_VDEV, 0);
+       }
+
+/* Terminate from IEEE1284 mode and release pdev block */
+       if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
+               w9966_pdev_claim(cam);
+               parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT);
+               w9966_pdev_release(cam);
+       }
+
+/* Unregister from parport */
+       if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
+               parport_unregister_device(cam->pdev);
+               w9966_setState(cam, W9966_STATE_PDEV, 0);
+       }
+}
+
 
 /* Called once for every parport on init */
 static void w9966_attach(struct parport *port)


---

Patch is available at: 
http://linuxtv.org/hg/v4l-dvb/rev/fc4e65dea1af2d87468df5d3e3ba3b5110ffd392

_______________________________________________
linuxtv-commits mailing list
[email protected]
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to