2 * QuickCam Driver For Video4Linux.
4 * Video4Linux conversion work by Alan Cox.
5 * Parport compatibility by Phil Blundell.
6 * Busy loop avoidance by Mark Cooke.
12 * When polling the QuickCam for a response, busy-wait for a
13 * maximum of this many loops. The default of 250 gives little
14 * impact on interactive response.
16 * NOTE: If this parameter is set too high, the processor
17 * will busy wait until this loop times out, and then
18 * slowly poll for a further 5 seconds before failing
19 * the transaction. You have been warned.
21 * yieldlines=<1 - 250>
23 * When acquiring a frame from the camera, the data gathering
24 * loop will yield back to the scheduler after completing
25 * this many lines. The default of 4 provides a trade-off
26 * between increased frame acquisition time and impact on
27 * interactive response.
30 /* qcam-lib.c -- Library for programming with the Connectix QuickCam.
31 * See the included documentation for usage instructions and details
32 * of the protocol involved. */
35 /* Version 0.5, August 4, 1996 */
36 /* Version 0.7, August 27, 1996 */
37 /* Version 0.9, November 17, 1996 */
40 /******************************************************************
42 Copyright (C) 1996 by Scott Laird
44 Permission is hereby granted, free of charge, to any person obtaining
45 a copy of this software and associated documentation files (the
46 "Software"), to deal in the Software without restriction, including
47 without limitation the rights to use, copy, modify, merge, publish,
48 distribute, sublicense, and/or sell copies of the Software, and to
49 permit persons to whom the Software is furnished to do so, subject to
50 the following conditions:
52 The above copyright notice and this permission notice shall be
53 included in all copies or substantial portions of the Software.
55 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58 IN NO EVENT SHALL SCOTT LAIRD BE LIABLE FOR ANY CLAIM, DAMAGES OR
59 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
60 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
61 OTHER DEALINGS IN THE SOFTWARE.
63 ******************************************************************/
65 #include <linux/module.h>
66 #include <linux/delay.h>
67 #include <linux/errno.h>
69 #include <linux/kernel.h>
70 #include <linux/slab.h>
72 #include <linux/parport.h>
73 #include <linux/sched.h>
74 #include <linux/videodev2.h>
75 #include <linux/mutex.h>
76 #include <asm/uaccess.h>
77 #include <media/v4l2-common.h>
78 #include <media/v4l2-ioctl.h>
79 #include <media/v4l2-device.h>
81 /* One from column A... */
87 /* ... and one from column B */
89 #define QC_FORCE_UNIDIR 0x10
90 #define QC_FORCE_BIDIR 0x20
91 #define QC_FORCE_SERIAL 0x30
92 /* in the port_mode member */
94 #define QC_MODE_MASK 0x07
95 #define QC_FORCE_MASK 0x70
97 #define MAX_HEIGHT 243
100 /* Bit fields for status flags */
101 #define QC_PARAM_CHANGE 0x01 /* Camera status change has occurred */
104 struct v4l2_device v4l2_dev
;
105 struct video_device vdev
;
106 struct pardevice
*pdev
;
107 struct parport
*pport
;
112 int contrast
, brightness
, whitebal
;
117 unsigned int saved_bits
;
118 unsigned long in_use
;
121 static unsigned int maxpoll
= 250; /* Maximum busy-loop count for qcam I/O */
122 static unsigned int yieldlines
= 4; /* Yield after this many during capture */
123 static int video_nr
= -1;
124 static unsigned int force_init
; /* Whether to probe aggressively */
126 module_param(maxpoll
, int, 0);
127 module_param(yieldlines
, int, 0);
128 module_param(video_nr
, int, 0);
130 /* Set force_init=1 to avoid detection by polling status register and
131 * immediately attempt to initialize qcam */
132 module_param(force_init
, int, 0);
135 static struct qcam
*qcams
[MAX_CAMS
];
136 static unsigned int num_cams
;
138 static inline int read_lpstatus(struct qcam
*q
)
140 return parport_read_status(q
->pport
);
143 static inline int read_lpdata(struct qcam
*q
)
145 return parport_read_data(q
->pport
);
148 static inline void write_lpdata(struct qcam
*q
, int d
)
150 parport_write_data(q
->pport
, d
);
153 static void write_lpcontrol(struct qcam
*q
, int d
)
156 /* Set bidirectional mode to reverse (data in) */
157 parport_data_reverse(q
->pport
);
159 /* Set bidirectional mode to forward (data out) */
160 parport_data_forward(q
->pport
);
163 /* Now issue the regular port command, but strip out the
166 parport_write_control(q
->pport
, d
);
170 /* qc_waithand busy-waits for a handshake signal from the QuickCam.
171 * Almost all communication with the camera requires handshaking. */
173 static int qc_waithand(struct qcam
*q
, int val
)
179 while (!((status
= read_lpstatus(q
)) & 8)) {
180 /* 1000 is enough spins on the I/O for all normal
181 cases, at that point we start to poll slowly
182 until the camera wakes up. However, we are
183 busy blocked until the camera responds, so
184 setting it lower is much better for interactive
187 if (runs
++ > maxpoll
)
188 msleep_interruptible(5);
189 if (runs
> (maxpoll
+ 1000)) /* 5 seconds */
193 while (((status
= read_lpstatus(q
)) & 8)) {
194 /* 1000 is enough spins on the I/O for all normal
195 cases, at that point we start to poll slowly
196 until the camera wakes up. However, we are
197 busy blocked until the camera responds, so
198 setting it lower is much better for interactive
201 if (runs
++ > maxpoll
)
202 msleep_interruptible(5);
203 if (runs
++ > (maxpoll
+ 1000)) /* 5 seconds */
211 /* Waithand2 is used when the qcam is in bidirectional mode, and the
212 * handshaking signal is CamRdy2 (bit 0 of data reg) instead of CamRdy1
213 * (bit 3 of status register). It also returns the last value read,
214 * since this data is useful. */
216 static unsigned int qc_waithand2(struct qcam
*q
, int val
)
222 status
= read_lpdata(q
);
223 /* 1000 is enough spins on the I/O for all normal
224 cases, at that point we start to poll slowly
225 until the camera wakes up. However, we are
226 busy blocked until the camera responds, so
227 setting it lower is much better for interactive
230 if (runs
++ > maxpoll
)
231 msleep_interruptible(5);
232 if (runs
++ > (maxpoll
+ 1000)) /* 5 seconds */
234 } while ((status
& 1) != val
);
239 /* qc_command is probably a bit of a misnomer -- it's used to send
240 * bytes *to* the camera. Generally, these bytes are either commands
241 * or arguments to commands, so the name fits, but it still bugs me a
242 * bit. See the documentation for a list of commands. */
244 static int qc_command(struct qcam
*q
, int command
)
249 write_lpdata(q
, command
);
250 write_lpcontrol(q
, 6);
252 n1
= qc_waithand(q
, 1);
254 write_lpcontrol(q
, 0xe);
255 n2
= qc_waithand(q
, 0);
257 cmd
= (n1
& 0xf0) | ((n2
& 0xf0) >> 4);
261 static int qc_readparam(struct qcam
*q
)
266 write_lpcontrol(q
, 6);
267 n1
= qc_waithand(q
, 1);
269 write_lpcontrol(q
, 0xe);
270 n2
= qc_waithand(q
, 0);
272 cmd
= (n1
& 0xf0) | ((n2
& 0xf0) >> 4);
277 /* Try to detect a QuickCam. It appears to flash the upper 4 bits of
278 the status register at 5-10 Hz. This is only used in the autoprobe
279 code. Be aware that this isn't the way Connectix detects the
280 camera (they send a reset and try to handshake), but this should be
281 almost completely safe, while their method screws up my printer if
282 I plug it in before the camera. */
284 static int qc_detect(struct qcam
*q
)
293 lastreg
= reg
= read_lpstatus(q
) & 0xf0;
295 for (i
= 0; i
< 500; i
++) {
296 reg
= read_lpstatus(q
) & 0xf0;
305 /* Force camera detection during testing. Sometimes the camera
306 won't be flashing these bits. Possibly unloading the module
307 in the middle of a grab? Or some timeout condition?
308 I've seen this parameter as low as 19 on my 450Mhz box - mpc */
309 printk(KERN_DEBUG
"Debugging: QCam detection counter <30-200 counts as detected>: %d\n", count
);
313 /* Be (even more) liberal in what you accept... */
315 if (count
> 20 && count
< 400) {
316 return 1; /* found */
318 printk(KERN_ERR
"No Quickcam found on port %s\n",
320 printk(KERN_DEBUG
"Quickcam detection counter: %u\n", count
);
321 return 0; /* not found */
325 /* Decide which scan mode to use. There's no real requirement that
326 * the scanmode match the resolution in q->height and q-> width -- the
327 * camera takes the picture at the resolution specified in the
328 * "scanmode" and then returns the image at the resolution specified
329 * with the resolution commands. If the scan is bigger than the
330 * requested resolution, the upper-left hand corner of the scan is
331 * returned. If the scan is smaller, then the rest of the image
332 * returned contains garbage. */
334 static int qc_setscanmode(struct qcam
*q
)
336 int old_mode
= q
->mode
;
338 switch (q
->transfer_scale
) {
358 switch (q
->port_mode
& QC_MODE_MASK
) {
367 if (q
->mode
!= old_mode
)
368 q
->status
|= QC_PARAM_CHANGE
;
374 /* Reset the QuickCam. This uses the same sequence the Windows
375 * QuickPic program uses. Someone with a bi-directional port should
376 * check that bi-directional mode is detected right, and then
377 * implement bi-directional mode in qc_readbyte(). */
379 static void qc_reset(struct qcam
*q
)
381 switch (q
->port_mode
& QC_FORCE_MASK
) {
382 case QC_FORCE_UNIDIR
:
383 q
->port_mode
= (q
->port_mode
& ~QC_MODE_MASK
) | QC_UNIDIR
;
387 q
->port_mode
= (q
->port_mode
& ~QC_MODE_MASK
) | QC_BIDIR
;
391 write_lpcontrol(q
, 0x20);
392 write_lpdata(q
, 0x75);
394 if (read_lpdata(q
) != 0x75)
395 q
->port_mode
= (q
->port_mode
& ~QC_MODE_MASK
) | QC_BIDIR
;
397 q
->port_mode
= (q
->port_mode
& ~QC_MODE_MASK
) | QC_UNIDIR
;
401 write_lpcontrol(q
, 0xb);
403 write_lpcontrol(q
, 0xe);
404 qc_setscanmode(q
); /* in case port_mode changed */
409 /* Reset the QuickCam and program for brightness, contrast,
410 * white-balance, and resolution. */
412 static void qc_set(struct qcam
*q
)
419 /* Set the brightness. Yes, this is repetitive, but it works.
420 * Shorter versions seem to fail subtly. Feel free to try :-). */
421 /* I think the problem was in qc_command, not here -- bls */
424 qc_command(q
, q
->brightness
);
426 val
= q
->height
/ q
->transfer_scale
;
429 if ((q
->port_mode
& QC_MODE_MASK
) == QC_UNIDIR
&& q
->bpp
== 6) {
430 /* The normal "transfers per line" calculation doesn't seem to work
431 as expected here (and yet it works fine in qc_scan). No idea
432 why this case is the odd man out. Fortunately, Laird's original
433 working version gives me a good way to guess at working values.
436 val2
= q
->transfer_scale
* 4;
438 val
= q
->width
* q
->bpp
;
439 val2
= (((q
->port_mode
& QC_MODE_MASK
) == QC_BIDIR
) ? 24 : 8) *
442 val
= DIV_ROUND_UP(val
, val2
);
446 /* Setting top and left -- bls */
448 qc_command(q
, q
->top
);
450 qc_command(q
, q
->left
/ 2);
453 qc_command(q
, q
->contrast
);
455 qc_command(q
, q
->whitebal
);
457 /* Clear flag that we must update the grabbing parameters on the camera
458 before we grab the next frame */
459 q
->status
&= (~QC_PARAM_CHANGE
);
462 /* Qc_readbytes reads some bytes from the QC and puts them in
463 the supplied buffer. It returns the number of bytes read,
466 static inline int qc_readbytes(struct qcam
*q
, char buffer
[])
470 unsigned int hi2
, lo2
;
473 if (buffer
== NULL
) {
478 switch (q
->port_mode
& QC_MODE_MASK
) {
479 case QC_BIDIR
: /* Bi-directional Port */
480 write_lpcontrol(q
, 0x26);
481 lo
= (qc_waithand2(q
, 1) >> 1);
482 hi
= (read_lpstatus(q
) >> 3) & 0x1f;
483 write_lpcontrol(q
, 0x2e);
484 lo2
= (qc_waithand2(q
, 0) >> 1);
485 hi2
= (read_lpstatus(q
) >> 3) & 0x1f;
488 buffer
[0] = lo
& 0xf;
489 buffer
[1] = ((lo
& 0x70) >> 4) | ((hi
& 1) << 3);
490 buffer
[2] = (hi
& 0x1e) >> 1;
491 buffer
[3] = lo2
& 0xf;
492 buffer
[4] = ((lo2
& 0x70) >> 4) | ((hi2
& 1) << 3);
493 buffer
[5] = (hi2
& 0x1e) >> 1;
497 buffer
[0] = lo
& 0x3f;
498 buffer
[1] = ((lo
& 0x40) >> 6) | (hi
<< 1);
499 buffer
[2] = lo2
& 0x3f;
500 buffer
[3] = ((lo2
& 0x40) >> 6) | (hi2
<< 1);
506 case QC_UNIDIR
: /* Unidirectional Port */
507 write_lpcontrol(q
, 6);
508 lo
= (qc_waithand(q
, 1) & 0xf0) >> 4;
509 write_lpcontrol(q
, 0xe);
510 hi
= (qc_waithand(q
, 0) & 0xf0) >> 4;
521 buffer
[0] = (lo
<< 2) | ((hi
& 0xc) >> 2);
522 q
->saved_bits
= (hi
& 3) << 4;
527 buffer
[0] = lo
| q
->saved_bits
;
528 q
->saved_bits
= hi
<< 2;
533 buffer
[0] = ((lo
& 0xc) >> 2) | q
->saved_bits
;
534 buffer
[1] = ((lo
& 3) << 4) | hi
;
546 /* requests a scan from the camera. It sends the correct instructions
547 * to the camera and then reads back the correct number of bytes. In
548 * previous versions of this routine the return structure contained
549 * the raw output from the camera, and there was a 'qc_convertscan'
550 * function that converted that to a useful format. In version 0.3 I
551 * rolled qc_convertscan into qc_scan and now I only return the
552 * converted scan. The format is just an one-dimensional array of
553 * characters, one for each pixel, with 0=black up to n=white, where
554 * n=2^(bit depth)-1. Ask me for more details if you don't understand
557 static long qc_capture(struct qcam
*q
, char __user
*buf
, unsigned long len
)
561 int linestotrans
, transperline
;
567 int shift
= 8 - q
->bpp
;
574 qc_command(q
, q
->mode
);
576 if ((q
->port_mode
& QC_MODE_MASK
) == QC_BIDIR
) {
577 write_lpcontrol(q
, 0x2e); /* turn port around */
578 write_lpcontrol(q
, 0x26);
580 write_lpcontrol(q
, 0x2e);
584 /* strange -- should be 15:63 below, but 4bpp is odd */
585 invert
= (q
->bpp
== 4) ? 16 : 63;
587 linestotrans
= q
->height
/ q
->transfer_scale
;
588 pixels_per_line
= q
->width
/ q
->transfer_scale
;
589 transperline
= q
->width
* q
->bpp
;
590 divisor
= (((q
->port_mode
& QC_MODE_MASK
) == QC_BIDIR
) ? 24 : 8) *
592 transperline
= DIV_ROUND_UP(transperline
, divisor
);
594 for (i
= 0, yield
= yieldlines
; i
< linestotrans
; i
++) {
595 for (pixels_read
= j
= 0; j
< transperline
; j
++) {
596 bytes
= qc_readbytes(q
, buffer
);
597 for (k
= 0; k
< bytes
&& (pixels_read
+ k
) < pixels_per_line
; k
++) {
599 if (buffer
[k
] == 0 && invert
== 16) {
600 /* 4bpp is odd (again) -- inverter is 16, not 15, but output
601 must be 0-15 -- bls */
604 o
= i
* pixels_per_line
+ pixels_read
+ k
;
607 put_user((invert
- buffer
[k
]) << shift
, buf
+ o
);
610 pixels_read
+= bytes
;
612 qc_readbytes(q
, NULL
); /* reset state machine */
614 /* Grabbing an entire frame from the quickcam is a lengthy
615 process. We don't (usually) want to busy-block the
616 processor for the entire frame. yieldlines is a module
617 parameter. If we yield every line, the minimum frame
618 time will be 240 / 200 = 1.2 seconds. The compile-time
619 default is to yield every 4 lines. */
621 msleep_interruptible(5);
622 yield
= i
+ yieldlines
;
626 if ((q
->port_mode
& QC_MODE_MASK
) == QC_BIDIR
) {
627 write_lpcontrol(q
, 2);
628 write_lpcontrol(q
, 6);
630 write_lpcontrol(q
, 0xe);
638 * Video4linux interfacing
641 static int qcam_querycap(struct file
*file
, void *priv
,
642 struct v4l2_capability
*vcap
)
644 struct qcam
*qcam
= video_drvdata(file
);
646 strlcpy(vcap
->driver
, qcam
->v4l2_dev
.name
, sizeof(vcap
->driver
));
647 strlcpy(vcap
->card
, "B&W Quickcam", sizeof(vcap
->card
));
648 strlcpy(vcap
->bus_info
, "parport", sizeof(vcap
->bus_info
));
649 vcap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
| V4L2_CAP_READWRITE
;
653 static int qcam_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*vin
)
657 strlcpy(vin
->name
, "Camera", sizeof(vin
->name
));
658 vin
->type
= V4L2_INPUT_TYPE_CAMERA
;
666 static int qcam_g_input(struct file
*file
, void *fh
, unsigned int *inp
)
672 static int qcam_s_input(struct file
*file
, void *fh
, unsigned int inp
)
674 return (inp
> 0) ? -EINVAL
: 0;
677 static int qcam_queryctrl(struct file
*file
, void *priv
,
678 struct v4l2_queryctrl
*qc
)
681 case V4L2_CID_BRIGHTNESS
:
682 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 180);
683 case V4L2_CID_CONTRAST
:
684 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 192);
686 return v4l2_ctrl_query_fill(qc
, 0, 255, 1, 105);
691 static int qcam_g_ctrl(struct file
*file
, void *priv
,
692 struct v4l2_control
*ctrl
)
694 struct qcam
*qcam
= video_drvdata(file
);
698 case V4L2_CID_BRIGHTNESS
:
699 ctrl
->value
= qcam
->brightness
;
701 case V4L2_CID_CONTRAST
:
702 ctrl
->value
= qcam
->contrast
;
705 ctrl
->value
= qcam
->whitebal
;
714 static int qcam_s_ctrl(struct file
*file
, void *priv
,
715 struct v4l2_control
*ctrl
)
717 struct qcam
*qcam
= video_drvdata(file
);
720 mutex_lock(&qcam
->lock
);
722 case V4L2_CID_BRIGHTNESS
:
723 qcam
->brightness
= ctrl
->value
;
725 case V4L2_CID_CONTRAST
:
726 qcam
->contrast
= ctrl
->value
;
729 qcam
->whitebal
= ctrl
->value
;
736 qc_setscanmode(qcam
);
737 qcam
->status
|= QC_PARAM_CHANGE
;
739 mutex_unlock(&qcam
->lock
);
743 static int qcam_g_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
745 struct qcam
*qcam
= video_drvdata(file
);
746 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
748 pix
->width
= qcam
->width
/ qcam
->transfer_scale
;
749 pix
->height
= qcam
->height
/ qcam
->transfer_scale
;
750 pix
->pixelformat
= (qcam
->bpp
== 4) ? V4L2_PIX_FMT_Y4
: V4L2_PIX_FMT_Y6
;
751 pix
->field
= V4L2_FIELD_NONE
;
752 pix
->bytesperline
= qcam
->width
;
753 pix
->sizeimage
= qcam
->width
* qcam
->height
;
755 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
759 static int qcam_try_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
761 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
763 if (pix
->height
<= 60 || pix
->width
<= 80) {
766 } else if (pix
->height
<= 120 || pix
->width
<= 160) {
773 if (pix
->pixelformat
!= V4L2_PIX_FMT_Y4
&&
774 pix
->pixelformat
!= V4L2_PIX_FMT_Y6
)
775 pix
->pixelformat
= V4L2_PIX_FMT_Y4
;
776 pix
->field
= V4L2_FIELD_NONE
;
777 pix
->bytesperline
= pix
->width
;
778 pix
->sizeimage
= pix
->width
* pix
->height
;
780 pix
->colorspace
= V4L2_COLORSPACE_SRGB
;
784 static int qcam_s_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_format
*fmt
)
786 struct qcam
*qcam
= video_drvdata(file
);
787 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
788 int ret
= qcam_try_fmt_vid_cap(file
, fh
, fmt
);
794 if (pix
->height
== 60)
795 qcam
->transfer_scale
= 4;
796 else if (pix
->height
== 120)
797 qcam
->transfer_scale
= 2;
799 qcam
->transfer_scale
= 1;
800 if (pix
->pixelformat
== V4L2_PIX_FMT_Y6
)
805 mutex_lock(&qcam
->lock
);
806 qc_setscanmode(qcam
);
807 /* We must update the camera before we grab. We could
808 just have changed the grab size */
809 qcam
->status
|= QC_PARAM_CHANGE
;
810 mutex_unlock(&qcam
->lock
);
814 static int qcam_enum_fmt_vid_cap(struct file
*file
, void *fh
, struct v4l2_fmtdesc
*fmt
)
816 static struct v4l2_fmtdesc formats
[] = {
818 "4-Bit Monochrome", V4L2_PIX_FMT_Y4
,
822 "6-Bit Monochrome", V4L2_PIX_FMT_Y6
,
826 enum v4l2_buf_type type
= fmt
->type
;
831 *fmt
= formats
[fmt
->index
];
836 static ssize_t
qcam_read(struct file
*file
, char __user
*buf
,
837 size_t count
, loff_t
*ppos
)
839 struct qcam
*qcam
= video_drvdata(file
);
841 parport_claim_or_block(qcam
->pdev
);
843 mutex_lock(&qcam
->lock
);
847 /* Update the camera parameters if we need to */
848 if (qcam
->status
& QC_PARAM_CHANGE
)
851 len
= qc_capture(qcam
, buf
, count
);
853 mutex_unlock(&qcam
->lock
);
855 parport_release(qcam
->pdev
);
859 static const struct v4l2_file_operations qcam_fops
= {
860 .owner
= THIS_MODULE
,
861 .unlocked_ioctl
= video_ioctl2
,
865 static const struct v4l2_ioctl_ops qcam_ioctl_ops
= {
866 .vidioc_querycap
= qcam_querycap
,
867 .vidioc_g_input
= qcam_g_input
,
868 .vidioc_s_input
= qcam_s_input
,
869 .vidioc_enum_input
= qcam_enum_input
,
870 .vidioc_queryctrl
= qcam_queryctrl
,
871 .vidioc_g_ctrl
= qcam_g_ctrl
,
872 .vidioc_s_ctrl
= qcam_s_ctrl
,
873 .vidioc_enum_fmt_vid_cap
= qcam_enum_fmt_vid_cap
,
874 .vidioc_g_fmt_vid_cap
= qcam_g_fmt_vid_cap
,
875 .vidioc_s_fmt_vid_cap
= qcam_s_fmt_vid_cap
,
876 .vidioc_try_fmt_vid_cap
= qcam_try_fmt_vid_cap
,
879 /* Initialize the QuickCam driver control structure. This is where
880 * defaults are set for people who don't have a config file.*/
882 static struct qcam
*qcam_init(struct parport
*port
)
885 struct v4l2_device
*v4l2_dev
;
887 qcam
= kzalloc(sizeof(struct qcam
), GFP_KERNEL
);
891 v4l2_dev
= &qcam
->v4l2_dev
;
892 strlcpy(v4l2_dev
->name
, "bw-qcam", sizeof(v4l2_dev
->name
));
894 if (v4l2_device_register(NULL
, v4l2_dev
) < 0) {
895 v4l2_err(v4l2_dev
, "Could not register v4l2_device\n");
901 qcam
->pdev
= parport_register_device(port
, "bw-qcam", NULL
, NULL
,
903 if (qcam
->pdev
== NULL
) {
904 v4l2_err(v4l2_dev
, "couldn't register for %s.\n", port
->name
);
909 strlcpy(qcam
->vdev
.name
, "Connectix QuickCam", sizeof(qcam
->vdev
.name
));
910 qcam
->vdev
.v4l2_dev
= v4l2_dev
;
911 qcam
->vdev
.fops
= &qcam_fops
;
912 qcam
->vdev
.ioctl_ops
= &qcam_ioctl_ops
;
913 qcam
->vdev
.release
= video_device_release_empty
;
914 video_set_drvdata(&qcam
->vdev
, qcam
);
916 mutex_init(&qcam
->lock
);
918 qcam
->port_mode
= (QC_ANY
| QC_NOTSET
);
922 qcam
->transfer_scale
= 2;
923 qcam
->contrast
= 192;
924 qcam
->brightness
= 180;
925 qcam
->whitebal
= 105;
929 qcam
->status
= QC_PARAM_CHANGE
;
933 static int qc_calibrate(struct qcam
*q
)
936 * Bugfix by Hanno Mueller hmueller@kabel.de, Mai 21 96
937 * The white balance is an individual value for each
944 qc_command(q
, 27); /* AutoAdjustOffset */
945 qc_command(q
, 0); /* Dummy Parameter, ignored by the camera */
947 /* GetOffset (33) will read 255 until autocalibration */
948 /* is finished. After that, a value of 1-254 will be */
953 value
= qc_readparam(q
);
957 } while (value
== 0xff && count
< 2048);
963 static int init_bwqcam(struct parport
*port
)
967 if (num_cams
== MAX_CAMS
) {
968 printk(KERN_ERR
"Too many Quickcams (max %d)\n", MAX_CAMS
);
972 qcam
= qcam_init(port
);
976 parport_claim_or_block(qcam
->pdev
);
980 if (qc_detect(qcam
) == 0) {
981 parport_release(qcam
->pdev
);
982 parport_unregister_device(qcam
->pdev
);
988 parport_release(qcam
->pdev
);
990 v4l2_info(&qcam
->v4l2_dev
, "Connectix Quickcam on %s\n", qcam
->pport
->name
);
992 if (video_register_device(&qcam
->vdev
, VFL_TYPE_GRABBER
, video_nr
) < 0) {
993 parport_unregister_device(qcam
->pdev
);
998 qcams
[num_cams
++] = qcam
;
1003 static void close_bwqcam(struct qcam
*qcam
)
1005 video_unregister_device(&qcam
->vdev
);
1006 parport_unregister_device(qcam
->pdev
);
1010 /* The parport parameter controls which parports will be scanned.
1011 * Scanning all parports causes some printers to print a garbage page.
1012 * -- March 14, 1999 Billy Donahue <billy@escape.com> */
1014 static char *parport
[MAX_CAMS
] = { NULL
, };
1015 module_param_array(parport
, charp
, NULL
, 0);
1018 static int accept_bwqcam(struct parport
*port
)
1023 if (parport
[0] && strncmp(parport
[0], "auto", 4) != 0) {
1024 /* user gave parport parameters */
1025 for (n
= 0; n
< MAX_CAMS
&& parport
[n
]; n
++) {
1028 r
= simple_strtoul(parport
[n
], &ep
, 0);
1029 if (ep
== parport
[n
]) {
1031 "bw-qcam: bad port specifier \"%s\"\n",
1035 if (r
== port
->number
)
1044 static void bwqcam_attach(struct parport
*port
)
1046 if (accept_bwqcam(port
))
1050 static void bwqcam_detach(struct parport
*port
)
1053 for (i
= 0; i
< num_cams
; i
++) {
1054 struct qcam
*qcam
= qcams
[i
];
1055 if (qcam
&& qcam
->pdev
->port
== port
) {
1062 static struct parport_driver bwqcam_driver
= {
1064 .attach
= bwqcam_attach
,
1065 .detach
= bwqcam_detach
,
1068 static void __exit
exit_bw_qcams(void)
1070 parport_unregister_driver(&bwqcam_driver
);
1073 static int __init
init_bw_qcams(void)
1076 /* Do some sanity checks on the module parameters. */
1077 if (maxpoll
> 5000) {
1078 printk(KERN_INFO
"Connectix Quickcam max-poll was above 5000. Using 5000.\n");
1082 if (yieldlines
< 1) {
1083 printk(KERN_INFO
"Connectix Quickcam yieldlines was less than 1. Using 1.\n");
1087 return parport_register_driver(&bwqcam_driver
);
1090 module_init(init_bw_qcams
);
1091 module_exit(exit_bw_qcams
);
1093 MODULE_LICENSE("GPL");
1094 MODULE_VERSION("0.0.3");