aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/bw-qcam.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/bw-qcam.c')
-rw-r--r--drivers/media/video/bw-qcam.c106
1 files changed, 53 insertions, 53 deletions
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index d97b7d8ac33d..cf61c590f4ad 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -150,7 +150,7 @@ static int qc_calibrate(struct qcam_device *q)
150static struct qcam_device *qcam_init(struct parport *port) 150static struct qcam_device *qcam_init(struct parport *port)
151{ 151{
152 struct qcam_device *q; 152 struct qcam_device *q;
153 153
154 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL); 154 q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
155 if(q==NULL) 155 if(q==NULL)
156 return NULL; 156 return NULL;
@@ -158,16 +158,16 @@ static struct qcam_device *qcam_init(struct parport *port)
158 q->pport = port; 158 q->pport = port;
159 q->pdev = parport_register_device(port, "bw-qcam", NULL, NULL, 159 q->pdev = parport_register_device(port, "bw-qcam", NULL, NULL,
160 NULL, 0, NULL); 160 NULL, 0, NULL);
161 if (q->pdev == NULL) 161 if (q->pdev == NULL)
162 { 162 {
163 printk(KERN_ERR "bw-qcam: couldn't register for %s.\n", 163 printk(KERN_ERR "bw-qcam: couldn't register for %s.\n",
164 port->name); 164 port->name);
165 kfree(q); 165 kfree(q);
166 return NULL; 166 return NULL;
167 } 167 }
168 168
169 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template)); 169 memcpy(&q->vdev, &qcam_template, sizeof(qcam_template));
170 170
171 mutex_init(&q->lock); 171 mutex_init(&q->lock);
172 172
173 q->port_mode = (QC_ANY | QC_NOTSET); 173 q->port_mode = (QC_ANY | QC_NOTSET);
@@ -236,12 +236,12 @@ static int qc_waithand(struct qcam_device *q, int val)
236 while (!((status = read_lpstatus(q)) & 8)) 236 while (!((status = read_lpstatus(q)) & 8))
237 { 237 {
238 /* 1000 is enough spins on the I/O for all normal 238 /* 1000 is enough spins on the I/O for all normal
239 cases, at that point we start to poll slowly 239 cases, at that point we start to poll slowly
240 until the camera wakes up. However, we are 240 until the camera wakes up. However, we are
241 busy blocked until the camera responds, so 241 busy blocked until the camera responds, so
242 setting it lower is much better for interactive 242 setting it lower is much better for interactive
243 response. */ 243 response. */
244 244
245 if(runs++>maxpoll) 245 if(runs++>maxpoll)
246 { 246 {
247 msleep_interruptible(5); 247 msleep_interruptible(5);
@@ -255,12 +255,12 @@ static int qc_waithand(struct qcam_device *q, int val)
255 while (((status = read_lpstatus(q)) & 8)) 255 while (((status = read_lpstatus(q)) & 8))
256 { 256 {
257 /* 1000 is enough spins on the I/O for all normal 257 /* 1000 is enough spins on the I/O for all normal
258 cases, at that point we start to poll slowly 258 cases, at that point we start to poll slowly
259 until the camera wakes up. However, we are 259 until the camera wakes up. However, we are
260 busy blocked until the camera responds, so 260 busy blocked until the camera responds, so
261 setting it lower is much better for interactive 261 setting it lower is much better for interactive
262 response. */ 262 response. */
263 263
264 if(runs++>maxpoll) 264 if(runs++>maxpoll)
265 { 265 {
266 msleep_interruptible(5); 266 msleep_interruptible(5);
@@ -282,17 +282,17 @@ static unsigned int qc_waithand2(struct qcam_device *q, int val)
282{ 282{
283 unsigned int status; 283 unsigned int status;
284 int runs=0; 284 int runs=0;
285 285
286 do 286 do
287 { 287 {
288 status = read_lpdata(q); 288 status = read_lpdata(q);
289 /* 1000 is enough spins on the I/O for all normal 289 /* 1000 is enough spins on the I/O for all normal
290 cases, at that point we start to poll slowly 290 cases, at that point we start to poll slowly
291 until the camera wakes up. However, we are 291 until the camera wakes up. However, we are
292 busy blocked until the camera responds, so 292 busy blocked until the camera responds, so
293 setting it lower is much better for interactive 293 setting it lower is much better for interactive
294 response. */ 294 response. */
295 295
296 if(runs++>maxpoll) 296 if(runs++>maxpoll)
297 { 297 {
298 msleep_interruptible(5); 298 msleep_interruptible(5);
@@ -321,7 +321,7 @@ static int qc_detect(struct qcam_device *q)
321 321
322 lastreg = reg = read_lpstatus(q) & 0xf0; 322 lastreg = reg = read_lpstatus(q) & 0xf0;
323 323
324 for (i = 0; i < 500; i++) 324 for (i = 0; i < 500; i++)
325 { 325 {
326 reg = read_lpstatus(q) & 0xf0; 326 reg = read_lpstatus(q) & 0xf0;
327 if (reg != lastreg) 327 if (reg != lastreg)
@@ -357,7 +357,7 @@ static int qc_detect(struct qcam_device *q)
357 357
358static void qc_reset(struct qcam_device *q) 358static void qc_reset(struct qcam_device *q)
359{ 359{
360 switch (q->port_mode & QC_FORCE_MASK) 360 switch (q->port_mode & QC_FORCE_MASK)
361 { 361 {
362 case QC_FORCE_UNIDIR: 362 case QC_FORCE_UNIDIR:
363 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR; 363 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
@@ -370,7 +370,7 @@ static void qc_reset(struct qcam_device *q)
370 case QC_ANY: 370 case QC_ANY:
371 write_lpcontrol(q, 0x20); 371 write_lpcontrol(q, 0x20);
372 write_lpdata(q, 0x75); 372 write_lpdata(q, 0x75);
373 373
374 if (read_lpdata(q) != 0x75) { 374 if (read_lpdata(q) != 0x75) {
375 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR; 375 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
376 } else { 376 } else {
@@ -398,8 +398,8 @@ static void qc_reset(struct qcam_device *q)
398static int qc_setscanmode(struct qcam_device *q) 398static int qc_setscanmode(struct qcam_device *q)
399{ 399{
400 int old_mode = q->mode; 400 int old_mode = q->mode;
401 401
402 switch (q->transfer_scale) 402 switch (q->transfer_scale)
403 { 403 {
404 case 1: 404 case 1:
405 q->mode = 0; 405 q->mode = 0;
@@ -412,7 +412,7 @@ static int qc_setscanmode(struct qcam_device *q)
412 break; 412 break;
413 } 413 }
414 414
415 switch (q->bpp) 415 switch (q->bpp)
416 { 416 {
417 case 4: 417 case 4:
418 break; 418 break;
@@ -421,7 +421,7 @@ static int qc_setscanmode(struct qcam_device *q)
421 break; 421 break;
422 } 422 }
423 423
424 switch (q->port_mode & QC_MODE_MASK) 424 switch (q->port_mode & QC_MODE_MASK)
425 { 425 {
426 case QC_BIDIR: 426 case QC_BIDIR:
427 q->mode += 1; 427 q->mode += 1;
@@ -430,10 +430,10 @@ static int qc_setscanmode(struct qcam_device *q)
430 case QC_UNIDIR: 430 case QC_UNIDIR:
431 break; 431 break;
432 } 432 }
433 433
434 if (q->mode != old_mode) 434 if (q->mode != old_mode)
435 q->status |= QC_PARAM_CHANGE; 435 q->status |= QC_PARAM_CHANGE;
436 436
437 return 0; 437 return 0;
438} 438}
439 439
@@ -451,7 +451,7 @@ static void qc_set(struct qcam_device *q)
451 /* Set the brightness. Yes, this is repetitive, but it works. 451 /* Set the brightness. Yes, this is repetitive, but it works.
452 * Shorter versions seem to fail subtly. Feel free to try :-). */ 452 * Shorter versions seem to fail subtly. Feel free to try :-). */
453 /* I think the problem was in qc_command, not here -- bls */ 453 /* I think the problem was in qc_command, not here -- bls */
454 454
455 qc_command(q, 0xb); 455 qc_command(q, 0xb);
456 qc_command(q, q->brightness); 456 qc_command(q, q->brightness);
457 457
@@ -502,13 +502,13 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
502 unsigned int hi2, lo2; 502 unsigned int hi2, lo2;
503 static int state = 0; 503 static int state = 0;
504 504
505 if (buffer == NULL) 505 if (buffer == NULL)
506 { 506 {
507 state = 0; 507 state = 0;
508 return 0; 508 return 0;
509 } 509 }
510 510
511 switch (q->port_mode & QC_MODE_MASK) 511 switch (q->port_mode & QC_MODE_MASK)
512 { 512 {
513 case QC_BIDIR: /* Bi-directional Port */ 513 case QC_BIDIR: /* Bi-directional Port */
514 write_lpcontrol(q, 0x26); 514 write_lpcontrol(q, 0x26);
@@ -517,7 +517,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
517 write_lpcontrol(q, 0x2e); 517 write_lpcontrol(q, 0x2e);
518 lo2 = (qc_waithand2(q, 0) >> 1); 518 lo2 = (qc_waithand2(q, 0) >> 1);
519 hi2 = (read_lpstatus(q) >> 3) & 0x1f; 519 hi2 = (read_lpstatus(q) >> 3) & 0x1f;
520 switch (q->bpp) 520 switch (q->bpp)
521 { 521 {
522 case 4: 522 case 4:
523 buffer[0] = lo & 0xf; 523 buffer[0] = lo & 0xf;
@@ -544,7 +544,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
544 write_lpcontrol(q, 0xe); 544 write_lpcontrol(q, 0xe);
545 hi = (qc_waithand(q, 0) & 0xf0) >> 4; 545 hi = (qc_waithand(q, 0) & 0xf0) >> 4;
546 546
547 switch (q->bpp) 547 switch (q->bpp)
548 { 548 {
549 case 4: 549 case 4:
550 buffer[0] = lo; 550 buffer[0] = lo;
@@ -552,7 +552,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
552 ret = 2; 552 ret = 2;
553 break; 553 break;
554 case 6: 554 case 6:
555 switch (state) 555 switch (state)
556 { 556 {
557 case 0: 557 case 0:
558 buffer[0] = (lo << 2) | ((hi & 0xc) >> 2); 558 buffer[0] = (lo << 2) | ((hi & 0xc) >> 2);
@@ -604,13 +604,13 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
604 int shift=8-q->bpp; 604 int shift=8-q->bpp;
605 char invert; 605 char invert;
606 606
607 if (q->mode == -1) 607 if (q->mode == -1)
608 return -ENXIO; 608 return -ENXIO;
609 609
610 qc_command(q, 0x7); 610 qc_command(q, 0x7);
611 qc_command(q, q->mode); 611 qc_command(q, q->mode);
612 612
613 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) 613 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
614 { 614 {
615 write_lpcontrol(q, 0x2e); /* turn port around */ 615 write_lpcontrol(q, 0x2e); /* turn port around */
616 write_lpcontrol(q, 0x26); 616 write_lpcontrol(q, 0x26);
@@ -618,7 +618,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
618 write_lpcontrol(q, 0x2e); 618 write_lpcontrol(q, 0x2e);
619 (void) qc_waithand(q, 0); 619 (void) qc_waithand(q, 0);
620 } 620 }
621 621
622 /* strange -- should be 15:63 below, but 4bpp is odd */ 622 /* strange -- should be 15:63 below, but 4bpp is odd */
623 invert = (q->bpp == 4) ? 16 : 63; 623 invert = (q->bpp == 4) ? 16 : 63;
624 624
@@ -629,15 +629,15 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
629 q->transfer_scale; 629 q->transfer_scale;
630 transperline = (transperline + divisor - 1) / divisor; 630 transperline = (transperline + divisor - 1) / divisor;
631 631
632 for (i = 0, yield = yieldlines; i < linestotrans; i++) 632 for (i = 0, yield = yieldlines; i < linestotrans; i++)
633 { 633 {
634 for (pixels_read = j = 0; j < transperline; j++) 634 for (pixels_read = j = 0; j < transperline; j++)
635 { 635 {
636 bytes = qc_readbytes(q, buffer); 636 bytes = qc_readbytes(q, buffer);
637 for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++) 637 for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++)
638 { 638 {
639 int o; 639 int o;
640 if (buffer[k] == 0 && invert == 16) 640 if (buffer[k] == 0 && invert == 16)
641 { 641 {
642 /* 4bpp is odd (again) -- inverter is 16, not 15, but output 642 /* 4bpp is odd (again) -- inverter is 16, not 15, but output
643 must be 0-15 -- bls */ 643 must be 0-15 -- bls */
@@ -653,7 +653,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
653 pixels_read += bytes; 653 pixels_read += bytes;
654 } 654 }
655 (void) qc_readbytes(q, NULL); /* reset state machine */ 655 (void) qc_readbytes(q, NULL); /* reset state machine */
656 656
657 /* Grabbing an entire frame from the quickcam is a lengthy 657 /* Grabbing an entire frame from the quickcam is a lengthy
658 process. We don't (usually) want to busy-block the 658 process. We don't (usually) want to busy-block the
659 processor for the entire frame. yieldlines is a module 659 processor for the entire frame. yieldlines is a module
@@ -666,7 +666,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
666 } 666 }
667 } 667 }
668 668
669 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) 669 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
670 { 670 {
671 write_lpcontrol(q, 2); 671 write_lpcontrol(q, 2);
672 write_lpcontrol(q, 6); 672 write_lpcontrol(q, 6);
@@ -687,7 +687,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
687{ 687{
688 struct video_device *dev = video_devdata(file); 688 struct video_device *dev = video_devdata(file);
689 struct qcam_device *qcam=(struct qcam_device *)dev; 689 struct qcam_device *qcam=(struct qcam_device *)dev;
690 690
691 switch(cmd) 691 switch(cmd)
692 { 692 {
693 case VIDIOCGCAP: 693 case VIDIOCGCAP:
@@ -762,7 +762,7 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
762 return -EINVAL; 762 return -EINVAL;
763 if(p->depth!=4 && p->depth!=6) 763 if(p->depth!=4 && p->depth!=6)
764 return -EINVAL; 764 return -EINVAL;
765 765
766 /* 766 /*
767 * Now load the camera. 767 * Now load the camera.
768 */ 768 */
@@ -790,11 +790,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
790 return -EINVAL; 790 return -EINVAL;
791 if(vw->width<80||vw->width>320) 791 if(vw->width<80||vw->width>320)
792 return -EINVAL; 792 return -EINVAL;
793 793
794 qcam->width = 320; 794 qcam->width = 320;
795 qcam->height = 240; 795 qcam->height = 240;
796 qcam->transfer_scale = 4; 796 qcam->transfer_scale = 4;
797 797
798 if(vw->width>=160 && vw->height>=120) 798 if(vw->width>=160 && vw->height>=120)
799 { 799 {
800 qcam->transfer_scale = 2; 800 qcam->transfer_scale = 2;
@@ -808,11 +808,11 @@ static int qcam_do_ioctl(struct inode *inode, struct file *file,
808 mutex_lock(&qcam->lock); 808 mutex_lock(&qcam->lock);
809 qc_setscanmode(qcam); 809 qc_setscanmode(qcam);
810 mutex_unlock(&qcam->lock); 810 mutex_unlock(&qcam->lock);
811 811
812 /* We must update the camera before we grab. We could 812 /* We must update the camera before we grab. We could
813 just have changed the grab size */ 813 just have changed the grab size */
814 qcam->status |= QC_PARAM_CHANGE; 814 qcam->status |= QC_PARAM_CHANGE;
815 815
816 /* Ok we figured out what to use from our wide choice */ 816 /* Ok we figured out what to use from our wide choice */
817 return 0; 817 return 0;
818 } 818 }
@@ -853,9 +853,9 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
853 struct qcam_device *qcam=(struct qcam_device *)v; 853 struct qcam_device *qcam=(struct qcam_device *)v;
854 int len; 854 int len;
855 parport_claim_or_block(qcam->pdev); 855 parport_claim_or_block(qcam->pdev);
856 856
857 mutex_lock(&qcam->lock); 857 mutex_lock(&qcam->lock);
858 858
859 qc_reset(qcam); 859 qc_reset(qcam);
860 860
861 /* Update the camera parameters if we need to */ 861 /* Update the camera parameters if we need to */
@@ -863,13 +863,13 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
863 qc_set(qcam); 863 qc_set(qcam);
864 864
865 len=qc_capture(qcam, buf,count); 865 len=qc_capture(qcam, buf,count);
866 866
867 mutex_unlock(&qcam->lock); 867 mutex_unlock(&qcam->lock);
868 868
869 parport_release(qcam->pdev); 869 parport_release(qcam->pdev);
870 return len; 870 return len;
871} 871}
872 872
873static struct file_operations qcam_fops = { 873static struct file_operations qcam_fops = {
874 .owner = THIS_MODULE, 874 .owner = THIS_MODULE,
875 .open = video_exclusive_open, 875 .open = video_exclusive_open,
@@ -905,11 +905,11 @@ static int init_bwqcam(struct parport *port)
905 qcam=qcam_init(port); 905 qcam=qcam_init(port);
906 if(qcam==NULL) 906 if(qcam==NULL)
907 return -ENODEV; 907 return -ENODEV;
908 908
909 parport_claim_or_block(qcam->pdev); 909 parport_claim_or_block(qcam->pdev);
910 910
911 qc_reset(qcam); 911 qc_reset(qcam);
912 912
913 if(qc_detect(qcam)==0) 913 if(qc_detect(qcam)==0)
914 { 914 {
915 parport_release(qcam->pdev); 915 parport_release(qcam->pdev);
@@ -920,9 +920,9 @@ static int init_bwqcam(struct parport *port)
920 qc_calibrate(qcam); 920 qc_calibrate(qcam);
921 921
922 parport_release(qcam->pdev); 922 parport_release(qcam->pdev);
923 923
924 printk(KERN_INFO "Connectix Quickcam on %s\n", qcam->pport->name); 924 printk(KERN_INFO "Connectix Quickcam on %s\n", qcam->pport->name);
925 925
926 if(video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr)==-1) 926 if(video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr)==-1)
927 { 927 {
928 parport_unregister_device(qcam->pdev); 928 parport_unregister_device(qcam->pdev);
@@ -1013,7 +1013,7 @@ static int __init init_bw_qcams(void)
1013 printk("Connectix Quickcam max-poll was above 5000. Using 5000.\n"); 1013 printk("Connectix Quickcam max-poll was above 5000. Using 5000.\n");
1014 maxpoll = 5000; 1014 maxpoll = 5000;
1015 } 1015 }
1016 1016
1017 if (yieldlines < 1) { 1017 if (yieldlines < 1) {
1018 printk("Connectix Quickcam yieldlines was less than 1. Using 1.\n"); 1018 printk("Connectix Quickcam yieldlines was less than 1. Using 1.\n");
1019 yieldlines = 1; 1019 yieldlines = 1;