2 * USB CPiA Video Camera driver
4 * Supports CPiA based Video Camera's. Many manufacturers use this chipset.
5 * There's a good chance, if you have a USB video camera, it's a CPiA based
8 * (C) Copyright 1999 Johannes Erdfelt
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/list.h>
14 #include <linux/malloc.h>
16 #include <linux/smp_lock.h>
17 #include <linux/videodev.h>
18 #include <linux/vmalloc.h>
19 #include <linux/wrapper.h>
20 #include <linux/module.h>
22 #include <asm/spinlock.h>
28 #define CPIA_DEBUG /* Gobs of debugging info */
30 #define MAX_FRAME_SIZE (384 * 288 * 3)
32 /*******************************/
33 /* Memory management functions */
34 /*******************************/
36 /* convert virtual user memory address to physical address */
37 /* (virt_to_phys only works for kmalloced kernel memory) */
39 static inline unsigned long uvirt_to_phys(unsigned long adr
)
45 pgd
= pgd_offset(current
->mm
, adr
);
48 pmd
= pmd_offset(pgd
, adr
);
51 ptep
= pte_offset(pmd
, adr
/*&(~PGDIR_MASK)*/);
55 virt_to_phys((void *)(pte_page(pte
)|(adr
&(PAGE_SIZE
-1))));
59 static inline unsigned long uvirt_to_bus(unsigned long adr
)
61 return virt_to_bus(phys_to_virt(uvirt_to_phys(adr
)));
64 /* convert virtual kernel memory address to physical address */
65 /* (virt_to_phys only works for kmalloced kernel memory) */
67 static inline unsigned long kvirt_to_phys(unsigned long adr
)
69 return uvirt_to_phys(VMALLOC_VMADDR(adr
));
72 static inline unsigned long kvirt_to_bus(unsigned long adr
)
74 return uvirt_to_bus(VMALLOC_VMADDR(adr
));
78 static void * rvmalloc(unsigned long size
)
81 unsigned long adr
, page
;
83 size
+= (PAGE_SIZE
- 1);
84 size
&= ~(PAGE_SIZE
- 1);
89 memset(mem
, 0, size
); /* Clear the ram out, no junk to the user */
90 adr
=(unsigned long) mem
;
93 page
= kvirt_to_phys(adr
);
94 mem_map_reserve(MAP_NR(phys_to_virt(page
)));
105 static void rvfree(void * mem
, unsigned long size
)
107 unsigned long adr
, page
;
109 size
+= (PAGE_SIZE
- 1);
110 size
&= ~(PAGE_SIZE
- 1);
114 adr
=(unsigned long) mem
;
117 page
= kvirt_to_phys(adr
);
118 mem_map_unreserve(MAP_NR(phys_to_virt(page
)));
120 if (size
> PAGE_SIZE
)
129 int usb_cpia_get_version(struct usb_device
*dev
, void *buf
)
133 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
) | 0x80;
134 dr
.request
= USB_REQ_CPIA_GET_VERSION
;
139 return dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
,0), &dr
, buf
, 4);
142 int usb_cpia_get_pnp_id(struct usb_device
*dev
, void *buf
)
146 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
) | 0x80;
147 dr
.request
= USB_REQ_CPIA_GET_PNP_ID
;
152 return dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
,0), &dr
, buf
, 6);
155 int usb_cpia_get_camera_status(struct usb_device
*dev
, void *buf
)
159 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
) | 0x80;
160 dr
.request
= USB_REQ_CPIA_GET_CAMERA_STATUS
;
165 return dev
->bus
->op
->control_msg(dev
, usb_rcvctrlpipe(dev
,0), &dr
, buf
, 8);
168 int usb_cpia_goto_hi_power(struct usb_device
*dev
)
172 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
173 dr
.request
= USB_REQ_CPIA_GOTO_HI_POWER
;
178 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
181 int usb_cpia_get_vp_version(struct usb_device
*dev
, void *buf
)
185 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
186 dr
.request
= USB_REQ_CPIA_GET_VP_VERSION
;
191 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, buf
, 4);
194 int usb_cpia_set_sensor_fps(struct usb_device
*dev
, int sensorbaserate
, int sensorclkdivisor
)
198 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
199 dr
.request
= USB_REQ_CPIA_SET_SENSOR_FPS
;
200 dr
.value
= (sensorclkdivisor
<< 8) + sensorbaserate
;
204 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
207 int usb_cpia_grab_frame(struct usb_device
*dev
, int streamstartline
)
211 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
212 dr
.request
= USB_REQ_CPIA_GRAB_FRAME
;
213 dr
.value
= streamstartline
<< 8;
217 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
220 int usb_cpia_upload_frame(struct usb_device
*dev
, int forceupload
)
224 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
225 dr
.request
= USB_REQ_CPIA_UPLOAD_FRAME
;
226 dr
.value
= forceupload
;
230 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
233 int usb_cpia_set_grab_mode(struct usb_device
*dev
, int continuousgrab
)
237 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
238 dr
.request
= USB_REQ_CPIA_SET_GRAB_MODE
;
239 dr
.value
= continuousgrab
;
243 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
246 int usb_cpia_set_format(struct usb_device
*dev
, int size
, int subsample
, int order
)
250 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
251 dr
.request
= USB_REQ_CPIA_SET_FORMAT
;
252 dr
.value
= (subsample
<< 8) + size
;
256 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
259 int usb_cpia_set_compression(struct usb_device
*dev
, int compmode
, int decimation
)
263 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
264 dr
.request
= USB_REQ_CPIA_SET_COMPRESSION
;
265 dr
.value
= (decimation
<< 8) + compmode
;
269 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
272 int usb_cpia_initstreamcap(struct usb_device
*dev
, int skipframes
, int streamstartline
)
276 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
277 dr
.request
= USB_REQ_CPIA_INIT_STREAM_CAP
;
278 dr
.value
= (streamstartline
<< 8) + skipframes
;
282 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
285 int usb_cpia_finistreamcap(struct usb_device
*dev
)
289 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
290 dr
.request
= USB_REQ_CPIA_FINI_STREAM_CAP
;
295 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
298 int usb_cpia_startstreamcap(struct usb_device
*dev
)
302 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
303 dr
.request
= USB_REQ_CPIA_START_STREAM_CAP
;
308 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
311 int usb_cpia_endstreamcap(struct usb_device
*dev
)
315 dr
.requesttype
= (USB_TYPE_VENDOR
| USB_RECIP_DEVICE
);
316 dr
.request
= USB_REQ_CPIA_END_STREAM_CAP
;
321 return dev
->bus
->op
->control_msg(dev
, usb_sndctrlpipe(dev
,0), &dr
, NULL
, 0);
324 /* How much data is left in the scratch buf? */
325 #define scratch_left(x) (cpia->scratchlen - (int)((char *)x - (char *)cpia->scratch))
327 static void cpia_parse_data(struct usb_cpia
*cpia
)
329 unsigned char *data
= cpia
->scratch
;
334 while (!done
&& scratch_left(data
)) {
335 switch (cpia
->state
) {
338 unsigned char *begin
= data
;
340 /* We need atleast 2 bytes for the magic value */
341 if (scratch_left(data
) < 2) {
346 /* 0x1968 is magic */
347 printk("header: %X\n", (*data
<< 8) + *(data
+ 1));
348 if ((*data
== 0x19) && (*(data
+ 1) == 0x68)) {
349 cpia
->state
= STATE_HEADER
;
350 printk("moving to header\n");
354 /* Woops, lost the header, find the end of the frame */
355 if (scratch_left(data
) < 4) {
360 printk("Scanning for end of frame\n");
361 while (scratch_left(data
) >= 4) {
362 if ((*data
== 0xFF) &&
363 (*(data
+ 1) == 0xFF) &&
364 (*(data
+ 2) == 0xFF) &&
365 (*(data
+ 3) == 0xFF)) {
372 printk("scan: scanned %d bytes\n", data
-begin
);
377 /* We need atleast 64 bytes for the header */
378 if (scratch_left(data
) < 64) {
384 printk("header: framerate %d\n", data
[41]);
389 cpia
->state
= STATE_LINES
;
394 unsigned char *begin
= data
;
397 while (scratch_left(data
)) {
402 } else if ((*data
== 0xFF) &&
403 (scratch_left(data
) >= 3) &&
404 (*(data
+ 1) == 0xFF) &&
405 (*(data
+ 2) == 0xFF) &&
406 (*(data
+ 3) == 0xFF)) {
416 if (data
-begin
== 355 && cpia
->frame
[cpia
->curframe
].width
!= 64) {
418 char *f
= cpia
->frame
[cpia
->curframe
].data
, *b
= begin
;
421 f
+= (cpia
->frame
[cpia
->curframe
].width
* 3) * cpia
->curline
;
423 for (i
= 0; i
< 176; i
++)
432 if (cpia
->curline
>= 144) {
434 cpia
->state
= STATE_SCANNING
;
449 /* Grab the remaining */
450 l
= scratch_left(data
);
451 memmove(cpia
->scratch
, data
, l
);
453 cpia
->scratchlen
= l
;
456 static int cpia_isoc_irq(int status
, void *__buffer
, int len
, void *dev_id
)
458 struct usb_cpia
*cpia
= dev_id
;
459 struct usb_device
*dev
= cpia
->dev
;
460 struct cpia_sbuf
*sbuf
;
464 if (!cpia
->streaming
) {
465 printk("oops, not streaming, but interrupt\n");
469 if (cpia
->curframe
< 0) {
470 if (cpia
->frame
[0].state
== FRAME_READY
) {
472 cpia
->frame
[0].state
= FRAME_GRABBING
;
474 printk("capturing to frame 0\n");
476 } else if (cpia
->frame
[1].state
== FRAME_READY
) {
478 cpia
->frame
[1].state
= FRAME_GRABBING
;
480 printk("capturing to frame 1\n");
484 printk("no frame available\n");
490 sbuf
= &cpia
->sbuf
[cpia
->receivesbuf
];
492 usb_unschedule_isochronous(dev
, sbuf
->isodesc
);
494 /* Do something to it now */
495 sbuf
->len
= usb_compress_isochronous(dev
, sbuf
->isodesc
);
499 printk("%d bytes received\n", sbuf
->len
);
502 if (sbuf
->len
&& cpia
->curframe
>= 0) {
503 if (sbuf
->len
> (SCRATCH_BUF_SIZE
- cpia
->scratchlen
)) {
504 printk("overflow!\n");
507 memcpy(cpia
->scratch
+ cpia
->scratchlen
, sbuf
->data
, sbuf
->len
);
508 cpia
->scratchlen
+= sbuf
->len
;
510 cpia_parse_data(cpia
);
513 /* Reschedule this block of Isochronous desc */
514 usb_schedule_isochronous(dev
, sbuf
->isodesc
, cpia
->sbuf
[(cpia
->receivesbuf
+ 2) % 3].isodesc
);
516 /* Move to the next one */
517 cpia
->receivesbuf
= (cpia
->receivesbuf
+ 1) % 3;
522 int cpia_init_isoc(struct usb_cpia
*cpia
)
524 struct usb_device
*dev
= cpia
->dev
;
526 cpia
->receivesbuf
= 0;
528 cpia
->scratchlen
= 0;
530 cpia
->state
= STATE_SCANNING
;
532 /* Allocate all of the memory necessary */
533 cpia
->sbuf
[0].isodesc
= usb_allocate_isochronous(dev
, usb_rcvisocpipe(dev
,1), cpia
->sbuf
[0].data
, STREAM_BUF_SIZE
, 960, cpia_isoc_irq
, cpia
);
534 cpia
->sbuf
[1].isodesc
= usb_allocate_isochronous(dev
, usb_rcvisocpipe(dev
,1), cpia
->sbuf
[1].data
, STREAM_BUF_SIZE
, 960, cpia_isoc_irq
, cpia
);
535 cpia
->sbuf
[2].isodesc
= usb_allocate_isochronous(dev
, usb_rcvisocpipe(dev
,1), cpia
->sbuf
[2].data
, STREAM_BUF_SIZE
, 960, cpia_isoc_irq
, cpia
);
538 printk("isodesc[0] @ %p\n", cpia
->sbuf
[0].isodesc
);
539 printk("isodesc[1] @ %p\n", cpia
->sbuf
[1].isodesc
);
540 printk("isodesc[2] @ %p\n", cpia
->sbuf
[2].isodesc
);
543 /* Schedule the queues */
544 usb_schedule_isochronous(dev
, cpia
->sbuf
[0].isodesc
, NULL
);
545 usb_schedule_isochronous(dev
, cpia
->sbuf
[1].isodesc
, cpia
->sbuf
[0].isodesc
);
546 usb_schedule_isochronous(dev
, cpia
->sbuf
[2].isodesc
, cpia
->sbuf
[1].isodesc
);
549 printk("done scheduling\n");
551 if (usb_set_interface(cpia
->dev
, 1, 3)) {
552 printk("cpia_set_interface error\n");
556 usb_cpia_startstreamcap(cpia
->dev
);
560 printk("now streaming\n");
566 void cpia_stop_isoc(struct usb_cpia
*cpia
)
568 struct usb_device
*dev
= cpia
->dev
;
570 if (!cpia
->streaming
)
575 /* Stop the streaming */
576 usb_cpia_endstreamcap(cpia
->dev
);
578 /* Set packet size to 0 */
579 if (usb_set_interface(cpia
->dev
, 1, 0)) {
580 printk("cpia_set_interface error\n");
581 return /* -EINVAL */;
584 /* Unschedule all of the iso td's */
585 usb_unschedule_isochronous(dev
, cpia
->sbuf
[2].isodesc
);
586 usb_unschedule_isochronous(dev
, cpia
->sbuf
[1].isodesc
);
587 usb_unschedule_isochronous(dev
, cpia
->sbuf
[0].isodesc
);
589 /* Delete them all */
590 usb_delete_isochronous(dev
, cpia
->sbuf
[2].isodesc
);
591 usb_delete_isochronous(dev
, cpia
->sbuf
[1].isodesc
);
592 usb_delete_isochronous(dev
, cpia
->sbuf
[0].isodesc
);
595 /* Video 4 Linux API */
596 static int cpia_open(struct video_device
*dev
, int flags
)
598 struct usb_cpia
*cpia
= (struct usb_cpia
*)dev
;
601 printk("cpia_open\n");
604 cpia
->fbuf
= rvmalloc(2 * MAX_FRAME_SIZE
);
608 cpia
->frame
[0].state
= FRAME_DONE
;
609 cpia
->frame
[1].state
= FRAME_DONE
;
611 cpia
->frame
[0].data
= cpia
->fbuf
;
612 cpia
->frame
[1].data
= cpia
->fbuf
+ MAX_FRAME_SIZE
;
614 printk("frame [0] @ %p\n", cpia
->frame
[0].data
);
615 printk("frame [1] @ %p\n", cpia
->frame
[1].data
);
618 cpia
->sbuf
[0].data
= kmalloc(STREAM_BUF_SIZE
, GFP_KERNEL
);
619 if (!cpia
->sbuf
[0].data
)
622 cpia
->sbuf
[1].data
= kmalloc(STREAM_BUF_SIZE
, GFP_KERNEL
);
623 if (!cpia
->sbuf
[1].data
)
626 cpia
->sbuf
[2].data
= kmalloc(STREAM_BUF_SIZE
, GFP_KERNEL
);
627 if (!cpia
->sbuf
[2].data
)
631 printk("sbuf[0] @ %p\n", cpia
->sbuf
[0].data
);
632 printk("sbuf[1] @ %p\n", cpia
->sbuf
[1].data
);
633 printk("sbuf[2] @ %p\n", cpia
->sbuf
[2].data
);
637 cpia
->receivesbuf
= 0;
639 usb_cpia_initstreamcap(cpia
->dev
, 0, 60);
641 cpia_init_isoc(cpia
);
646 kfree (cpia
->sbuf
[1].data
);
648 kfree (cpia
->sbuf
[0].data
);
650 rvfree(cpia
->fbuf
, 2 * MAX_FRAME_SIZE
);
655 static void cpia_close(struct video_device
*dev
)
657 struct usb_cpia
*cpia
= (struct usb_cpia
*)dev
;
660 printk("cpia_close\n");
663 cpia_stop_isoc(cpia
);
665 usb_cpia_finistreamcap(cpia
->dev
);
667 rvfree(cpia
->fbuf
, 2 * MAX_FRAME_SIZE
);
669 kfree(cpia
->sbuf
[2].data
);
670 kfree(cpia
->sbuf
[1].data
);
671 kfree(cpia
->sbuf
[0].data
);
674 static int cpia_init_done(struct video_device
*dev
)
679 static long cpia_write(struct video_device
*dev
, const char *buf
, unsigned long count
, int noblock
)
684 static int cpia_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
686 struct usb_cpia
*cpia
= (struct usb_cpia
*)dev
;
691 struct video_capability b
;
693 strcpy(b
.name
, "CPiA USB Camera");
694 b
.type
= VID_TYPE_CAPTURE
/* | VID_TYPE_SUBCAPTURE */;
697 b
.maxwidth
= 176 /* 352 */;
698 b
.maxheight
= 144 /* 240 */;
699 b
.minwidth
= 176 /* (Something small?) */;
700 b
.minheight
= 144 /* " " */;
702 if (copy_to_user(arg
, &b
, sizeof(b
)))
708 struct video_channel v
;
710 if (copy_from_user(&v
, arg
, sizeof(v
)))
717 v
.type
= VIDEO_TYPE_CAMERA
;
718 strcpy(v
.name
, "Camera");
720 if (copy_to_user(arg
, &v
, sizeof(v
)))
728 if (copy_from_user(&v
, arg
, sizeof(v
)))
738 struct video_tuner v
;
740 if (copy_from_user(&v
, arg
, sizeof(v
)))
746 strcpy(v
.name
, "Format");
751 v
.mode
= VIDEO_MODE_AUTO
;
753 if (copy_to_user(arg
, &v
, sizeof(v
)))
760 struct video_tuner v
;
762 if (copy_from_user(&v
, arg
, sizeof(v
)))
768 if (v
.mode
!= VIDEO_MODE_AUTO
)
775 struct video_picture p
;
777 p
.colour
= 0x8000; /* Damn British people :) */
779 p
.brightness
= 180 << 8; /* XXX */
780 p
.contrast
= 192 << 8; /* XXX */
781 p
.whiteness
= 105 << 8; /* XXX */
786 p
.palette
= VIDEO_PALETTE_YUYV
;
788 if (copy_to_user(arg
, &p
, sizeof(p
)))
795 struct video_picture p
;
797 if (copy_from_user(&p
, arg
, sizeof(p
)))
801 printk("Attempting to set palette %d, depth %d\n",
809 struct video_window vw
;
812 printk("VIDIOCSWIN\n");
815 if (copy_from_user(&vw
, arg
, sizeof(vw
)))
821 if (vw
.height
!= 176)
830 struct video_window vw
;
833 printk("VIDIOCGWIN\n");
843 if (copy_to_user(arg
, &vw
, sizeof(vw
)))
850 struct video_mbuf vm
;
852 memset(&vm
, 0, sizeof(vm
));
853 vm
.size
= MAX_FRAME_SIZE
* 2;
856 vm
.offsets
[1] = MAX_FRAME_SIZE
;
858 if (copy_to_user((void *)arg
, (void *)&vm
, sizeof(vm
)))
865 struct video_mmap vm
;
867 if (copy_from_user((void *)&vm
, (void *)arg
, sizeof(vm
)))
871 printk("MCAPTURE\n");
872 printk("frame: %d, size: %dx%d, format: %d\n",
873 vm
.frame
, vm
.width
, vm
.height
, vm
.format
);
876 if (vm
.format
!= VIDEO_PALETTE_RGB24
)
879 if ((vm
.frame
!= 0) && (vm
.frame
!= 1))
882 cpia
->frame
[vm
.frame
].width
= vm
.width
;
883 cpia
->frame
[vm
.frame
].height
= vm
.height
;
885 /* Mark it as free */
886 cpia
->frame
[vm
.frame
].state
= FRAME_READY
;
894 if (copy_from_user((void *)&frame
, arg
, sizeof(int)))
898 printk("syncing to frame %d\n", frame
);
900 switch (cpia
->frame
[frame
].state
) {
905 interruptible_sleep_on(&cpia
->wq
);
907 cpia
->frame
[frame
].state
= FRAME_UNUSED
;
911 printk("synced to frame %d\n", frame
);
937 static long cpia_read(struct video_device
*dev
, char *buf
, unsigned long count
, int noblock
)
939 struct usb_cpia
*cpia
= (struct usb_cpia
*)dev
;
943 printk("cpia_read: %ld bytes\n", count
);
946 len
= cpia_capture(cpia
, buf
, count
);
953 static int cpia_mmap(struct video_device
*dev
, const char *adr
, unsigned long size
)
955 struct usb_cpia
*cpia
= (struct usb_cpia
*)dev
;
956 unsigned long start
= (unsigned long)adr
;
957 unsigned long page
, pos
;
960 printk("mmap: %ld (%lX) bytes\n", size
, size
);
962 if (size
> (((2 * MAX_FRAME_SIZE
) + PAGE_SIZE
- 1) & ~(PAGE_SIZE
- 1)))
965 pos
= (unsigned long)cpia
->fbuf
;
968 page
= kvirt_to_phys(pos
);
969 if (remap_page_range(start
, page
, PAGE_SIZE
, PAGE_SHARED
))
973 if (size
> PAGE_SIZE
)
982 static struct video_device cpia_template
= {
999 static void usb_cpia_configure(struct usb_cpia
*cpia
)
1001 struct usb_device
*dev
= cpia
->dev
;
1002 unsigned char version
[4];
1003 unsigned char pnpid
[6];
1004 unsigned char camerastat
[8];
1007 if (usb_set_configuration(dev
, dev
->config
[0].bConfigurationValue
)) {
1008 printk (KERN_INFO
" Failed usb_set_configuration: CPIA\n");
1012 if (usb_cpia_get_version(dev
, version
)) {
1013 printk("cpia_get_version error\n");
1017 printk("cpia: Firmware v%d.%d, VC Hardware v%d.%d\n",
1018 version
[0], version
[1], version
[2], version
[3]);
1020 if (usb_cpia_get_pnp_id(dev
, pnpid
)) {
1021 printk("cpia_get_pnp_id error\n");
1025 printk("cpia: PnP Id: Vendor: %X, Product: %X, Revision: %X\n",
1026 (pnpid
[1] << 8) + pnpid
[0], (pnpid
[3] << 8) + pnpid
[2],
1027 (pnpid
[5] << 8) + pnpid
[4]);
1029 memcpy(&cpia
->vdev
, &cpia_template
, sizeof(cpia_template
));
1031 init_waitqueue_head(&cpia
->wq
);
1033 if (video_register_device(&cpia
->vdev
, VFL_TYPE_GRABBER
) == -1) {
1034 printk("video_register_device failed\n");
1038 if (usb_cpia_goto_hi_power(dev
)) {
1039 printk("cpia_goto_hi_power error\n");
1043 if (usb_cpia_get_vp_version(dev
, version
)) {
1044 printk("cpia_get_vp_version error\n");
1048 printk("cpia: VP v%d rev %d\n", version
[0], version
[1]);
1049 printk("cpia: Camera Head ID %04X\n", (version
[3] << 8) + version
[2]);
1051 /* Turn off continuous grab */
1052 if (usb_cpia_set_grab_mode(dev
, 1)) {
1053 printk("cpia_set_grab_mode error\n");
1057 /* Set up the sensor to be 30fps */
1058 if (usb_cpia_set_sensor_fps(dev
, 1, 0)) {
1059 printk("cpia_set_sensor_fps error\n");
1063 /* Set video into QCIF mode, and order into YUYV mode */
1064 if (usb_cpia_set_format(dev
, CPIA_QCIF
, 1, CPIA_YUYV
)) {
1065 printk("cpia_set_format error\n");
1069 /* Turn off compression */
1070 if (usb_cpia_set_compression(dev
, 0, 0)) {
1071 printk("cpia_set_compression error\n");
1076 static int cpia_probe(struct usb_device
*dev
)
1078 struct usb_interface_descriptor
*interface
;
1079 struct usb_endpoint_descriptor
*endpoint
;
1080 struct usb_cpia
*cpia
;
1082 /* We don't handle multi-config cameras */
1083 if (dev
->descriptor
.bNumConfigurations
!= 1)
1086 interface
= &dev
->config
[0].interface
[0].altsetting
[0];
1089 if (dev
->descriptor
.idVendor
!= 0x0553)
1091 if (dev
->descriptor
.idProduct
!= 0x0002)
1093 if (interface
->bInterfaceClass
!= 0xFF)
1095 if (interface
->bInterfaceSubClass
!= 0x00)
1098 /* We found a CPiA */
1099 printk("USB CPiA camera found\n");
1101 if ((cpia
= kmalloc(sizeof(*cpia
), GFP_KERNEL
)) == NULL
) {
1102 printk("couldn't kmalloc cpia struct\n");
1106 memset(cpia
, 0, sizeof(*cpia
));
1108 dev
->private = cpia
;
1111 usb_cpia_configure(cpia
);
1116 static void cpia_disconnect(struct usb_device
*dev
)
1118 struct usb_cpia
*cpia
= dev
->private;
1120 video_unregister_device(&cpia
->vdev
);
1122 /* Free the memory */
1126 static struct usb_driver cpia_driver
= {
1134 * This should be a separate module.
1136 int usb_cpia_init(void)
1138 usb_register(&cpia_driver
);
1144 int init_module(void)
1146 return usb_cpia_init();
1149 void cleanup_module(void)