[cpia] I Solved all the QX3 Microscope problems (2.4up) Fixed!!! REALLY!

Sam Alexander sam102@crpud.net
Mon, 4 Feb 2002 17:11:26 -0800


Ok, download the CVS version (currently 1.2) of the cpia driver. I am using
the 2.4.7-10 (default with Red Hat linux 7.2)

[root@squid source]# tar -xvzf cpia-1.2
[root@squid source]# cd cpia-1.2/module
[root@squid module]# make
Should get these errors:

echo '# Program dependencies' >.depend
gcc -M -D_CPIA_DEBUG_ -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer  -p
ipe
-fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions
=2 -
DCPU=686 -fomit-frame-pointer -fno-strength-reduce -I. -I/usr/src/linux/incl
ude
-D__KERNEL__ -DMODULE -DCONFIG_VIDEO_CPIA_MODULE -DCONFIG_VIDEO_CPIA_PP_MODU
LE -
DCONFIG_VIDEO_CPIA_PP_DMA  cpia.c cpia_pp.c  >>.depend
gcc -c -D_CPIA_DEBUG_ -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer  -p
ipe
-fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions
=2 -
DCPU=686 -fomit-frame-pointer -fno-strength-reduce -I. -I/usr/src/linux/incl
ude
-D__KERNEL__ -DMODULE -DCONFIG_VIDEO_CPIA_MODULE -DCONFIG_VIDEO_CPIA_PP_MODU
LE -
DCONFIG_VIDEO_CPIA_PP_DMA  cpia.c
cpia.c: In function `cpia_write_proc':
cpia.c:652: warning: `val' might be used uninitialized in this function
cpia.c: At top level:
cpia.c:3906: warning: initialization from incompatible pointer type
cpia.c:3907: warning: missing braces around initializer
cpia.c:3907: warning: (near initialization for `cpia_template.name')
cpia.c:3909: warning: initialization makes integer from pointer without a
cast
cpia.c:3909: initializer element is not computable at load time
cpia.c:3909: (near initialization for `cpia_template.name[2]')
cpia.c:3910: warning: initialization makes integer from pointer without a
cast
cpia.c:3910: initializer element is not computable at load time
cpia.c:3910: (near initialization for `cpia_template.name[3]')
cpia.c:3911: warning: initialization makes integer from pointer without a
cast
cpia.c:3911: initializer element is not computable at load time
cpia.c:3911: (near initialization for `cpia_template.name[4]')
cpia.c:3912: warning: initialization makes integer from pointer without a
cast
cpia.c:3913: warning: initialization makes integer from pointer without a
cast
cpia.c:3914: warning: initialization makes integer from pointer without a
cast
cpia.c:3914: initializer element is not computable at load time
cpia.c:3914: (near initialization for `cpia_template.name[7]')
cpia.c:3915: warning: initialization makes integer from pointer without a
cast
cpia.c:3915: initializer element is not computable at load time
cpia.c:3915: (near initialization for `cpia_template.name[8]')
cpia.c:3916: warning: initialization makes integer from pointer without a
cast
cpia.c:3916: initializer element is not computable at load time
cpia.c:3916: (near initialization for `cpia_template.name[9]')
cpia.c:3917: warning: initialization makes integer from pointer without a
cast
cpia.c: In function `cpia_register_camera':
cpia.c:4079: too few arguments to function `video_register_device'
make: *** [cpia.o] Error 1

After a few hours research I managed to edit the source so that it will
compile with out error!
The problem is that cpia.c attempts to create a video_device structure which
is missing the first argument, which in turn throws off all proceeding
values (explains errors on lines 3906 through 3917)
All other programs that create video_device structures have the first
argument THIS_MODULE, except for cpia.c
Simply follow these steps to fix that:
[root@squid module]# pico cpia.c

Change this:
static struct video_device cpia_template = {
        "CPiA Camera",
        VID_TYPE_CAPTURE,
        VID_HARDWARE_CPIA,
        cpia_open,              /* open */
        cpia_close,             /* close */
        cpia_read,              /* read */
        NULL,                   /* no write */
        NULL,                   /* no poll */
        cpia_ioctl,             /* ioctl */
        cpia_mmap,              /* mmap */
        cpia_video_init,        /* initialize */
        NULL,                   /* priv */
        0,                      /* busy */
        -1                      /* minor - unset */
};

To this:
static struct video_device cpia_template = {
        THIS_MODULE,
        "CPiA Camera",
        VID_TYPE_CAPTURE,
        VID_HARDWARE_CPIA,
        cpia_open,              /* open */
        cpia_close,             /* close */
        cpia_read,              /* read */
        NULL,                   /* no write */
        NULL,                   /* no poll */
        cpia_ioctl,             /* ioctl */
        cpia_mmap,              /* mmap */
        cpia_video_init,        /* initialize */
        NULL,                   /* priv */
        0,                      /* busy */
        -1                      /* minor - unset */
};


Save and exit then remake:
[root@squid module]# make
You should get this output:

gcc -c -D_CPIA_DEBUG_ -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer  -p
ipe -fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-funct
ions=2 -DCPU=686 -fomit-frame-pointer -fno-strength-reduce -I. -I/usr/src/li
nux/include -D__KERNEL__ -DMODULE -DCONFIG_VIDEO_CPIA_MODULE -DCONFIG_VIDEO_
CPIA_PP_MODULE -DCONFIG_VIDEO_CPIA_PP_DMA  cpia.c
cpia.c: In function `cpia_write_proc':
cpia.c:652: warning: `val' might be used uninitialized in this function
cpia.c: In function `cpia_register_camera':
cpia.c:4080: too few arguments to function `video_register_device'
make: *** [cpia.o] Error 1

Aha!! quite a few less errors hm? It seems that the call to
video_register_device requires three values and not two, like in cpia.c. I
worked through some more source and found that it requires the third
argument video_nr, which most modules use the value "-1". I'm not sure about
this but it works fine, you might want to see what video_nr actually means,
but every source file I found used the value -1. To fix this:
[root@squid module]# pico cpia.c
change this:
        if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER) == -1) {
to this:
        if (video_register_device(&camera->vdev, VFL_TYPE_GRABBER, -1)
== -1) {

Save exit and remake!
[root@squid module]# make
And it compiles succesfully!
Now insert the modules into the kernel!

[root@squid module]# insmod cpia.o
Using the old cpia_usb.o and old videodev.o modules will work fine with the
new cpia driver! That's it! Then you can use the proc interface... for
example:
[root@squid module]# echo "toplight: on" > /proc/cpia/video0
For some reason this only works if gqcam is running... hm need to fix that,
probly has to do something with it being on standby or something.
[root@squid module]# cat /proc/cpia/video0
This command shows all readable/writeable entries in /proc/cpia/video0

Please reply because I want to know if this helps anyone! Thanks.

--Sam Alexander