Portability cleanup as required by Linus.
[linux-2.6/linux-mips.git] / drivers / char / c-qcam.c
blobfa96cc925923ed0ed8141883a2e47e853ce75bb2
1 /*
2 * Video4Linux Colour QuickCam driver
3 * Copyright 1997-2000 Philip Blundell <philb@gnu.org>
5 * Module parameters:
7 * parport=auto -- probe all parports (default)
8 * parport=0 -- parport0 becomes qcam1
9 * parport=2,0,1 -- parports 2,0,1 are tried in that order
11 * probe=0 -- do no probing, assume camera is present
12 * probe=1 -- use IEEE-1284 autoprobe data only (default)
13 * probe=2 -- probe aggressively for cameras
15 * force_rgb=1 -- force data format to RGB (default is BGR)
17 * The parport parameter controls which parports will be scanned.
18 * Scanning all parports causes some printers to print a garbage page.
19 * -- March 14, 1999 Billy Donahue <billy@escape.com>
21 * Fixed data format to BGR, added force_rgb parameter. Added missing
22 * parport_unregister_driver() on module removal.
23 * -- May 28, 2000 Claudio Matsuoka <claudio@conectiva.com>
26 #include <linux/module.h>
27 #include <linux/delay.h>
28 #include <linux/errno.h>
29 #include <linux/fs.h>
30 #include <linux/init.h>
31 #include <linux/kernel.h>
32 #include <linux/malloc.h>
33 #include <linux/mm.h>
34 #include <linux/parport.h>
35 #include <linux/sched.h>
36 #include <linux/version.h>
37 #include <linux/videodev.h>
38 #include <asm/semaphore.h>
39 #include <asm/uaccess.h>
41 struct qcam_device {
42 struct video_device vdev;
43 struct pardevice *pdev;
44 struct parport *pport;
45 int width, height;
46 int ccd_width, ccd_height;
47 int mode;
48 int contrast, brightness, whitebal;
49 int top, left;
50 unsigned int bidirectional;
51 struct semaphore lock;
54 /* cameras maximum */
55 #define MAX_CAMS 4
57 /* The three possible QuickCam modes */
58 #define QC_MILLIONS 0x18
59 #define QC_BILLIONS 0x10
60 #define QC_THOUSANDS 0x08 /* with VIDEC compression (not supported) */
62 /* The three possible decimations */
63 #define QC_DECIMATION_1 0
64 #define QC_DECIMATION_2 2
65 #define QC_DECIMATION_4 4
67 #define BANNER "Colour QuickCam for Video4Linux v0.05"
69 static int parport[MAX_CAMS] = { [1 ... MAX_CAMS-1] = -1 };
70 static int probe = 2;
71 static int force_rgb = 0;
73 static inline void qcam_set_ack(struct qcam_device *qcam, unsigned int i)
75 /* note: the QC specs refer to the PCAck pin by voltage, not
76 software level. PC ports have builtin inverters. */
77 parport_frob_control(qcam->pport, 8, i?8:0);
80 static inline unsigned int qcam_ready1(struct qcam_device *qcam)
82 return (parport_read_status(qcam->pport) & 0x8)?1:0;
85 static inline unsigned int qcam_ready2(struct qcam_device *qcam)
87 return (parport_read_data(qcam->pport) & 0x1)?1:0;
90 static unsigned int qcam_await_ready1(struct qcam_device *qcam,
91 int value)
93 unsigned long oldjiffies = jiffies;
94 unsigned int i;
96 for (oldjiffies = jiffies; (jiffies - oldjiffies) < (HZ/25); )
97 if (qcam_ready1(qcam) == value)
98 return 0;
100 /* If the camera didn't respond within 1/25 second, poll slowly
101 for a while. */
102 for (i = 0; i < 50; i++)
104 if (qcam_ready1(qcam) == value)
105 return 0;
106 current->state=TASK_INTERRUPTIBLE;
107 schedule_timeout(HZ/10);
110 /* Probably somebody pulled the plug out. Not much we can do. */
111 printk(KERN_ERR "c-qcam: ready1 timeout (%d) %x %x\n", value,
112 parport_read_status(qcam->pport),
113 parport_read_control(qcam->pport));
114 return 1;
117 static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
119 unsigned long oldjiffies = jiffies;
120 unsigned int i;
122 for (oldjiffies = jiffies; (jiffies - oldjiffies) < (HZ/25); )
123 if (qcam_ready2(qcam) == value)
124 return 0;
126 /* If the camera didn't respond within 1/25 second, poll slowly
127 for a while. */
128 for (i = 0; i < 50; i++)
130 if (qcam_ready2(qcam) == value)
131 return 0;
132 current->state=TASK_INTERRUPTIBLE;
133 schedule_timeout(HZ/10);
136 /* Probably somebody pulled the plug out. Not much we can do. */
137 printk(KERN_ERR "c-qcam: ready2 timeout (%d) %x %x %x\n", value,
138 parport_read_status(qcam->pport),
139 parport_read_control(qcam->pport),
140 parport_read_data(qcam->pport));
141 return 1;
144 static int qcam_read_data(struct qcam_device *qcam)
146 unsigned int idata;
147 qcam_set_ack(qcam, 0);
148 if (qcam_await_ready1(qcam, 1)) return -1;
149 idata = parport_read_status(qcam->pport) & 0xf0;
150 qcam_set_ack(qcam, 1);
151 if (qcam_await_ready1(qcam, 0)) return -1;
152 idata |= (parport_read_status(qcam->pport) >> 4);
153 return idata;
156 static int qcam_write_data(struct qcam_device *qcam, unsigned int data)
158 unsigned int idata;
159 parport_write_data(qcam->pport, data);
160 idata = qcam_read_data(qcam);
161 if (data != idata)
163 printk(KERN_WARNING "cqcam: sent %x but received %x\n", data,
164 idata);
165 return 1;
167 return 0;
170 static inline int qcam_set(struct qcam_device *qcam, unsigned int cmd, unsigned int data)
172 if (qcam_write_data(qcam, cmd))
173 return -1;
174 if (qcam_write_data(qcam, data))
175 return -1;
176 return 0;
179 static inline int qcam_get(struct qcam_device *qcam, unsigned int cmd)
181 if (qcam_write_data(qcam, cmd))
182 return -1;
183 return qcam_read_data(qcam);
186 static int qc_detect(struct qcam_device *qcam)
188 unsigned int stat, ostat, i, count = 0;
190 /* The probe routine below is not very reliable. The IEEE-1284
191 probe takes precedence. */
192 /* XXX Currently parport provides no way to distinguish between
193 "the IEEE probe was not done" and "the probe was done, but
194 no device was found". Fix this one day. */
195 if (qcam->pport->probe_info[0].class == PARPORT_CLASS_MEDIA
196 && qcam->pport->probe_info[0].model
197 && !strcmp(qcam->pdev->port->probe_info[0].model,
198 "Color QuickCam 2.0")) {
199 printk(KERN_DEBUG "QuickCam: Found by IEEE1284 probe.\n");
200 return 1;
203 if (probe < 2)
204 return 0;
206 parport_write_control(qcam->pport, 0xc);
208 /* look for a heartbeat */
209 ostat = stat = parport_read_status(qcam->pport);
210 for (i=0; i<250; i++)
212 mdelay(1);
213 stat = parport_read_status(qcam->pport);
214 if (ostat != stat)
216 if (++count >= 3) return 1;
217 ostat = stat;
221 /* Reset the camera and try again */
222 parport_write_control(qcam->pport, 0xc);
223 parport_write_control(qcam->pport, 0x8);
224 mdelay(1);
225 parport_write_control(qcam->pport, 0xc);
226 mdelay(1);
227 count = 0;
229 ostat = stat = parport_read_status(qcam->pport);
230 for (i=0; i<250; i++)
232 mdelay(1);
233 stat = parport_read_status(qcam->pport);
234 if (ostat != stat)
236 if (++count >= 3) return 1;
237 ostat = stat;
241 /* no (or flatline) camera, give up */
242 return 0;
245 static void qc_reset(struct qcam_device *qcam)
247 parport_write_control(qcam->pport, 0xc);
248 parport_write_control(qcam->pport, 0x8);
249 mdelay(1);
250 parport_write_control(qcam->pport, 0xc);
251 mdelay(1);
254 /* Reset the QuickCam and program for brightness, contrast,
255 * white-balance, and resolution. */
257 static void qc_setup(struct qcam_device *q)
259 qc_reset(q);
261 /* Set the brightness. */
262 qcam_set(q, 11, q->brightness);
264 /* Set the height and width. These refer to the actual
265 CCD area *before* applying the selected decimation. */
266 qcam_set(q, 17, q->ccd_height);
267 qcam_set(q, 19, q->ccd_width / 2);
269 /* Set top and left. */
270 qcam_set(q, 0xd, q->top);
271 qcam_set(q, 0xf, q->left);
273 /* Set contrast and white balance. */
274 qcam_set(q, 0x19, q->contrast);
275 qcam_set(q, 0x1f, q->whitebal);
277 /* Set the speed. */
278 qcam_set(q, 45, 2);
281 /* Read some bytes from the camera and put them in the buffer.
282 nbytes should be a multiple of 3, because bidirectional mode gives
283 us three bytes at a time. */
285 static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, unsigned int nbytes)
287 unsigned int bytes = 0;
289 qcam_set_ack(q, 0);
290 if (q->bidirectional)
292 /* It's a bidirectional port */
293 while (bytes < nbytes)
295 unsigned int lo1, hi1, lo2, hi2;
296 unsigned char r, g, b;
298 if (qcam_await_ready2(q, 1)) return bytes;
299 lo1 = parport_read_data(q->pport) >> 1;
300 hi1 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10;
301 qcam_set_ack(q, 1);
302 if (qcam_await_ready2(q, 0)) return bytes;
303 lo2 = parport_read_data(q->pport) >> 1;
304 hi2 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10;
305 qcam_set_ack(q, 0);
306 r = (lo1 | ((hi1 & 1)<<7));
307 g = ((hi1 & 0x1e)<<3) | ((hi2 & 0x1e)>>1);
308 b = (lo2 | ((hi2 & 1)<<7));
309 if (force_rgb) {
310 buf[bytes++] = r;
311 buf[bytes++] = g;
312 buf[bytes++] = b;
313 } else {
314 buf[bytes++] = b;
315 buf[bytes++] = g;
316 buf[bytes++] = r;
320 else
322 /* It's a unidirectional port */
323 int i = 0, n = bytes;
324 unsigned char rgb[3];
326 while (bytes < nbytes)
328 unsigned int hi, lo;
330 if (qcam_await_ready1(q, 1)) return bytes;
331 hi = (parport_read_status(q->pport) & 0xf0);
332 qcam_set_ack(q, 1);
333 if (qcam_await_ready1(q, 0)) return bytes;
334 lo = (parport_read_status(q->pport) & 0xf0);
335 qcam_set_ack(q, 0);
336 /* flip some bits */
337 rgb[(i = bytes++ % 3)] = (hi | (lo >> 4)) ^ 0x88;
338 if (i >= 2) {
339 get_fragment:
340 if (force_rgb) {
341 buf[n++] = rgb[0];
342 buf[n++] = rgb[1];
343 buf[n++] = rgb[2];
344 } else {
345 buf[n++] = rgb[2];
346 buf[n++] = rgb[1];
347 buf[n++] = rgb[0];
351 if (i) {
352 i = 0;
353 goto get_fragment;
356 return bytes;
359 #define BUFSZ 150
361 static long qc_capture(struct qcam_device *q, char *buf, unsigned long len)
363 unsigned lines, pixelsperline, bitsperxfer;
364 unsigned int is_bi_dir = q->bidirectional;
365 size_t wantlen, outptr = 0;
366 char tmpbuf[BUFSZ];
368 if (verify_area(VERIFY_WRITE, buf, len))
369 return -EFAULT;
371 /* Wait for camera to become ready */
372 for (;;)
374 int i = qcam_get(q, 41);
375 if (i == -1) {
376 qc_setup(q);
377 return -EIO;
379 if ((i & 0x80) == 0)
380 break;
381 else
382 schedule();
385 if (qcam_set(q, 7, (q->mode | (is_bi_dir?1:0)) + 1))
386 return -EIO;
388 lines = q->height;
389 pixelsperline = q->width;
390 bitsperxfer = (is_bi_dir) ? 24 : 8;
392 if (is_bi_dir)
394 /* Turn the port around */
395 parport_data_reverse(q->pport);
396 mdelay(3);
397 qcam_set_ack(q, 0);
398 if (qcam_await_ready1(q, 1)) {
399 qc_setup(q);
400 return -EIO;
402 qcam_set_ack(q, 1);
403 if (qcam_await_ready1(q, 0)) {
404 qc_setup(q);
405 return -EIO;
409 wantlen = lines * pixelsperline * 24 / 8;
411 while (wantlen)
413 size_t t, s;
414 s = (wantlen > BUFSZ)?BUFSZ:wantlen;
415 t = qcam_read_bytes(q, tmpbuf, s);
416 if (outptr < len)
418 size_t sz = len - outptr;
419 if (sz > t) sz = t;
420 if (__copy_to_user(buf+outptr, tmpbuf, sz))
421 break;
422 outptr += sz;
424 wantlen -= t;
425 if (t < s)
426 break;
427 if (current->need_resched)
428 schedule();
431 len = outptr;
433 if (wantlen)
435 printk("qcam: short read.\n");
436 if (is_bi_dir)
437 parport_data_forward(q->pport);
438 qc_setup(q);
439 return len;
442 if (is_bi_dir)
444 int l;
445 do {
446 l = qcam_read_bytes(q, tmpbuf, 3);
447 if (current->need_resched)
448 schedule();
449 } while (l && (tmpbuf[0] == 0x7e || tmpbuf[1] == 0x7e || tmpbuf[2] == 0x7e));
450 if (force_rgb) {
451 if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
452 printk("qcam: bad EOF\n");
453 } else {
454 if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
455 printk("qcam: bad EOF\n");
457 qcam_set_ack(q, 0);
458 if (qcam_await_ready1(q, 1))
460 printk("qcam: no ack after EOF\n");
461 parport_data_forward(q->pport);
462 qc_setup(q);
463 return len;
465 parport_data_forward(q->pport);
466 mdelay(3);
467 qcam_set_ack(q, 1);
468 if (qcam_await_ready1(q, 0))
470 printk("qcam: no ack to port turnaround\n");
471 qc_setup(q);
472 return len;
475 else
477 int l;
478 do {
479 l = qcam_read_bytes(q, tmpbuf, 1);
480 if (current->need_resched)
481 schedule();
482 } while (l && tmpbuf[0] == 0x7e);
483 l = qcam_read_bytes(q, tmpbuf+1, 2);
484 if (force_rgb) {
485 if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
486 printk("qcam: bad EOF\n");
487 } else {
488 if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
489 printk("qcam: bad EOF\n");
493 qcam_write_data(q, 0);
494 return len;
498 * Video4linux interfacing
501 static int qcam_open(struct video_device *dev, int flags)
503 MOD_INC_USE_COUNT;
504 return 0;
507 static void qcam_close(struct video_device *dev)
509 MOD_DEC_USE_COUNT;
512 static int qcam_init_done(struct video_device *dev)
514 return 0;
517 static long qcam_write(struct video_device *v, const char *buf, unsigned long count, int noblock)
519 return -EINVAL;
522 static int qcam_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
524 struct qcam_device *qcam=(struct qcam_device *)dev;
526 switch(cmd)
528 case VIDIOCGCAP:
530 struct video_capability b;
531 strcpy(b.name, "Quickcam");
532 b.type = VID_TYPE_CAPTURE|VID_TYPE_SCALES;
533 b.channels = 1;
534 b.audios = 0;
535 b.maxwidth = 320;
536 b.maxheight = 240;
537 b.minwidth = 80;
538 b.minheight = 60;
539 if(copy_to_user(arg, &b,sizeof(b)))
540 return -EFAULT;
541 return 0;
543 case VIDIOCGCHAN:
545 struct video_channel v;
546 if(copy_from_user(&v, arg, sizeof(v)))
547 return -EFAULT;
548 if(v.channel!=0)
549 return -EINVAL;
550 v.flags=0;
551 v.tuners=0;
552 /* Good question.. its composite or SVHS so.. */
553 v.type = VIDEO_TYPE_CAMERA;
554 strcpy(v.name, "Camera");
555 if(copy_to_user(arg, &v, sizeof(v)))
556 return -EFAULT;
557 return 0;
559 case VIDIOCSCHAN:
561 int v;
562 if(copy_from_user(&v, arg,sizeof(v)))
563 return -EFAULT;
564 if(v!=0)
565 return -EINVAL;
566 return 0;
568 case VIDIOCGTUNER:
570 struct video_tuner v;
571 if(copy_from_user(&v, arg, sizeof(v))!=0)
572 return -EFAULT;
573 if(v.tuner)
574 return -EINVAL;
575 strcpy(v.name, "Format");
576 v.rangelow=0;
577 v.rangehigh=0;
578 v.flags= 0;
579 v.mode = VIDEO_MODE_AUTO;
580 if(copy_to_user(arg,&v,sizeof(v))!=0)
581 return -EFAULT;
582 return 0;
584 case VIDIOCSTUNER:
586 struct video_tuner v;
587 if(copy_from_user(&v, arg, sizeof(v))!=0)
588 return -EFAULT;
589 if(v.tuner)
590 return -EINVAL;
591 if(v.mode!=VIDEO_MODE_AUTO)
592 return -EINVAL;
593 return 0;
595 case VIDIOCGPICT:
597 struct video_picture p;
598 p.colour=0x8000;
599 p.hue=0x8000;
600 p.brightness=qcam->brightness<<8;
601 p.contrast=qcam->contrast<<8;
602 p.whiteness=qcam->whitebal<<8;
603 p.depth=24;
604 p.palette=VIDEO_PALETTE_RGB24;
605 if(copy_to_user(arg, &p, sizeof(p)))
606 return -EFAULT;
607 return 0;
609 case VIDIOCSPICT:
611 struct video_picture p;
612 if(copy_from_user(&p, arg, sizeof(p)))
613 return -EFAULT;
616 * Sanity check args
618 if (p.depth != 24 || p.palette != VIDEO_PALETTE_RGB24)
619 return -EINVAL;
622 * Now load the camera.
624 qcam->brightness = p.brightness>>8;
625 qcam->contrast = p.contrast>>8;
626 qcam->whitebal = p.whiteness>>8;
628 down(&qcam->lock);
629 parport_claim_or_block(qcam->pdev);
630 qc_setup(qcam);
631 parport_release(qcam->pdev);
632 up(&qcam->lock);
633 return 0;
635 case VIDIOCSWIN:
637 struct video_window vw;
639 if(copy_from_user(&vw, arg,sizeof(vw)))
640 return -EFAULT;
641 if(vw.flags)
642 return -EINVAL;
643 if(vw.clipcount)
644 return -EINVAL;
645 if(vw.height<60||vw.height>240)
646 return -EINVAL;
647 if(vw.width<80||vw.width>320)
648 return -EINVAL;
650 qcam->width = 80;
651 qcam->height = 60;
652 qcam->mode = QC_DECIMATION_4;
654 if(vw.width>=160 && vw.height>=120)
656 qcam->width = 160;
657 qcam->height = 120;
658 qcam->mode = QC_DECIMATION_2;
660 if(vw.width>=320 && vw.height>=240)
662 qcam->width = 320;
663 qcam->height = 240;
664 qcam->mode = QC_DECIMATION_1;
666 qcam->mode |= QC_MILLIONS;
667 #if 0
668 if(vw.width>=640 && vw.height>=480)
670 qcam->width = 640;
671 qcam->height = 480;
672 qcam->mode = QC_BILLIONS | QC_DECIMATION_1;
674 #endif
675 /* Ok we figured out what to use from our
676 wide choice */
677 down(&qcam->lock);
678 parport_claim_or_block(qcam->pdev);
679 qc_setup(qcam);
680 parport_release(qcam->pdev);
681 up(&qcam->lock);
682 return 0;
684 case VIDIOCGWIN:
686 struct video_window vw;
687 vw.x=0;
688 vw.y=0;
689 vw.width=qcam->width;
690 vw.height=qcam->height;
691 vw.chromakey=0;
692 vw.flags=0;
693 if(copy_to_user(arg, &vw, sizeof(vw)))
694 return -EFAULT;
695 return 0;
697 case VIDIOCCAPTURE:
698 return -EINVAL;
699 case VIDIOCGFBUF:
700 return -EINVAL;
701 case VIDIOCSFBUF:
702 return -EINVAL;
703 case VIDIOCKEY:
704 return 0;
705 case VIDIOCGFREQ:
706 return -EINVAL;
707 case VIDIOCSFREQ:
708 return -EINVAL;
709 case VIDIOCGAUDIO:
710 return -EINVAL;
711 case VIDIOCSAUDIO:
712 return -EINVAL;
713 default:
714 return -ENOIOCTLCMD;
716 return 0;
719 static long qcam_read(struct video_device *v, char *buf, unsigned long count, int noblock)
721 struct qcam_device *qcam=(struct qcam_device *)v;
722 int len;
724 down(&qcam->lock);
725 parport_claim_or_block(qcam->pdev);
726 /* Probably should have a semaphore against multiple users */
727 len = qc_capture(qcam, buf,count);
728 parport_release(qcam->pdev);
729 up(&qcam->lock);
730 return len;
733 /* video device template */
734 static struct video_device qcam_template=
736 "Colour QuickCam",
737 VID_TYPE_CAPTURE,
738 VID_HARDWARE_QCAM_C,
739 qcam_open,
740 qcam_close,
741 qcam_read,
742 qcam_write,
743 NULL,
744 qcam_ioctl,
745 NULL,
746 qcam_init_done,
747 NULL,
752 /* Initialize the QuickCam driver control structure. */
754 static struct qcam_device *qcam_init(struct parport *port)
756 struct qcam_device *q;
758 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
759 if(q==NULL)
760 return NULL;
762 q->pport = port;
763 q->pdev = parport_register_device(port, "c-qcam", NULL, NULL,
764 NULL, 0, NULL);
766 q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE)?1:0;
768 if (q->pdev == NULL)
770 printk(KERN_ERR "c-qcam: couldn't register for %s.\n",
771 port->name);
772 kfree(q);
773 return NULL;
776 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template));
778 init_MUTEX(&q->lock);
779 q->width = q->ccd_width = 320;
780 q->height = q->ccd_height = 240;
781 q->mode = QC_MILLIONS | QC_DECIMATION_1;
782 q->contrast = 192;
783 q->brightness = 240;
784 q->whitebal = 128;
785 q->top = 1;
786 q->left = 14;
787 return q;
790 static struct qcam_device *qcams[MAX_CAMS];
791 static unsigned int num_cams = 0;
793 int init_cqcam(struct parport *port)
795 struct qcam_device *qcam;
797 if (parport[0] != -1)
799 /* The user gave specific instructions */
800 int i, found = 0;
801 for (i = 0; i < MAX_CAMS && parport[i] != -1; i++)
803 if (parport[0] == port->number)
804 found = 1;
806 if (!found)
807 return -ENODEV;
810 if (num_cams == MAX_CAMS)
811 return -ENOSPC;
813 qcam = qcam_init(port);
814 if (qcam==NULL)
815 return -ENODEV;
817 parport_claim_or_block(qcam->pdev);
819 qc_reset(qcam);
821 if (probe && qc_detect(qcam)==0)
823 parport_release(qcam->pdev);
824 parport_unregister_device(qcam->pdev);
825 kfree(qcam);
826 return -ENODEV;
829 qc_setup(qcam);
831 parport_release(qcam->pdev);
833 if (video_register_device(&qcam->vdev, VFL_TYPE_GRABBER)==-1)
835 printk(KERN_ERR "Unable to register Colour QuickCam on %s\n",
836 qcam->pport->name);
837 parport_unregister_device(qcam->pdev);
838 kfree(qcam);
839 return -ENODEV;
842 printk(KERN_INFO "video%d: Colour QuickCam found on %s\n",
843 qcam->vdev.minor, qcam->pport->name);
845 qcams[num_cams++] = qcam;
847 return 0;
850 void close_cqcam(struct qcam_device *qcam)
852 video_unregister_device(&qcam->vdev);
853 parport_unregister_device(qcam->pdev);
854 kfree(qcam);
857 static void cq_attach(struct parport *port)
859 init_cqcam(port);
862 static void cq_detach(struct parport *port)
864 /* Write this some day. */
867 static struct parport_driver cqcam_driver = {
868 "cqcam",
869 cq_attach,
870 cq_detach,
871 NULL
874 static int __init cqcam_init (void)
876 printk(BANNER "\n");
878 return parport_register_driver(&cqcam_driver);
881 static void __exit cqcam_cleanup (void)
883 unsigned int i;
885 for (i = 0; i < num_cams; i++)
886 close_cqcam(qcams[i]);
888 parport_unregister_driver(&cqcam_driver);
891 MODULE_AUTHOR("Philip Blundell <philb@gnu.org>");
892 MODULE_DESCRIPTION(BANNER);
893 MODULE_PARM_DESC(parport ,"parport=<auto|n[,n]...> for port detection method\n\
894 probe=<0|1|2> for camera detection method\n\
895 force_rgb=<0|1> for RGB data format (default BGR)");
896 MODULE_PARM(parport, "1-" __MODULE_STRING(MAX_CAMS) "i");
897 MODULE_PARM(probe, "i");
898 MODULE_PARM(force_rgb, "i");
900 module_init(cqcam_init);
901 module_exit(cqcam_cleanup);