aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/sunplus.c
diff options
context:
space:
mode:
authorJean-Francois Moine <moinejf@free.fr>2008-07-14 08:38:29 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-07-20 06:26:14 -0400
commit739570bb218bb4607df1f197282561e97a98e54a (patch)
tree25555dfe5ac873bc96866c486d6f6c1dcabf24f4 /drivers/media/video/gspca/sunplus.c
parent5b77ae7776183d733ec86727bcc34c52a336afd6 (diff)
V4L/DVB (8352): gspca: Buffers for USB exchanges cannot be in the stack.
gspca: Protect dq_callback() against simultaneous USB exchanges. Temporary buffer for USB exchanges added in the device struct. (all) Use a temporary buffer for all USB exchanges. Signed-off-by: Jean-Francois Moine <moinejf@free.fr> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/gspca/sunplus.c')
-rw-r--r--drivers/media/video/gspca/sunplus.c279
1 files changed, 138 insertions, 141 deletions
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index f66594a113a7..acd4a077198a 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -24,8 +24,8 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 5) 27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.5"; 28static const char version[] = "2.1.7";
29 29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver"); 31MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver");
@@ -452,7 +452,7 @@ static const __u8 qtable_spca504_default[2][64] = {
452 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e} 452 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
453}; 453};
454 454
455static void spca5xxRegRead(struct usb_device *dev, 455static void reg_r(struct usb_device *dev,
456 __u16 req, 456 __u16 req,
457 __u16 index, 457 __u16 index,
458 __u8 *buffer, __u16 length) 458 __u8 *buffer, __u16 length)
@@ -466,7 +466,7 @@ static void spca5xxRegRead(struct usb_device *dev,
466 500); 466 500);
467} 467}
468 468
469static void spca5xxRegWrite(struct usb_device *dev, 469static void reg_w(struct usb_device *dev,
470 __u16 req, 470 __u16 req,
471 __u16 value, 471 __u16 value,
472 __u16 index, 472 __u16 index,
@@ -480,7 +480,8 @@ static void spca5xxRegWrite(struct usb_device *dev,
480 500); 480 500);
481} 481}
482 482
483static int reg_write(struct usb_device *dev, 483/* write req / index / value */
484static int reg_w_riv(struct usb_device *dev,
484 __u16 req, __u16 index, __u16 value) 485 __u16 req, __u16 index, __u16 value)
485{ 486{
486 int ret; 487 int ret;
@@ -490,57 +491,56 @@ static int reg_write(struct usb_device *dev,
490 req, 491 req,
491 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 492 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
492 value, index, NULL, 0, 500); 493 value, index, NULL, 0, 500);
493 PDEBUG(D_PACK, "reg write: 0x%02x,0x%02x:0x%02x, 0x%x", 494 PDEBUG(D_USBO, "reg write: 0x%02x,0x%02x:0x%02x, %d",
494 req, index, value, ret); 495 req, index, value, ret);
495 if (ret < 0) 496 if (ret < 0)
496 PDEBUG(D_ERR, "reg write: error %d", ret); 497 PDEBUG(D_ERR, "reg write: error %d", ret);
497 return ret; 498 return ret;
498} 499}
499 500
500static int reg_read_info(struct usb_device *dev, 501/* read 1 byte */
502static int reg_r_1(struct gspca_dev *gspca_dev,
501 __u16 value) /* wValue */ 503 __u16 value) /* wValue */
502{ 504{
503 int ret; 505 int ret;
504 __u8 data;
505 506
506 ret = usb_control_msg(dev, 507 ret = usb_control_msg(gspca_dev->dev,
507 usb_rcvctrlpipe(dev, 0), 508 usb_rcvctrlpipe(gspca_dev->dev, 0),
508 0x20, /* request */ 509 0x20, /* request */
509 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 510 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
510 value, 511 value,
511 0, /* index */ 512 0, /* index */
512 &data, 1, 513 gspca_dev->usb_buf, 1,
513 500); /* timeout */ 514 500); /* timeout */
514 if (ret < 0) { 515 if (ret < 0) {
515 PDEBUG(D_ERR, "reg_read_info err %d", ret); 516 PDEBUG(D_ERR, "reg_r_1 err %d", ret);
516 return 0; 517 return 0;
517 } 518 }
518 return data; 519 return gspca_dev->usb_buf[0];
519} 520}
520 521
521/* returns: negative is error, pos or zero is data */ 522/* read 1 or 2 bytes - returns < 0 if error */
522static int reg_read(struct usb_device *dev, 523static int reg_r_12(struct gspca_dev *gspca_dev,
523 __u16 req, /* bRequest */ 524 __u16 req, /* bRequest */
524 __u16 index, /* wIndex */ 525 __u16 index, /* wIndex */
525 __u16 length) /* wLength (1 or 2 only) */ 526 __u16 length) /* wLength (1 or 2 only) */
526{ 527{
527 int ret; 528 int ret;
528 __u8 buf[2];
529 529
530 buf[1] = 0; 530 gspca_dev->usb_buf[1] = 0;
531 ret = usb_control_msg(dev, 531 ret = usb_control_msg(gspca_dev->dev,
532 usb_rcvctrlpipe(dev, 0), 532 usb_rcvctrlpipe(gspca_dev->dev, 0),
533 req, 533 req,
534 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 534 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
535 0, /* value */ 535 0, /* value */
536 index, 536 index,
537 buf, length, 537 gspca_dev->usb_buf, length,
538 500); 538 500);
539 if (ret < 0) { 539 if (ret < 0) {
540 PDEBUG(D_ERR, "reg_read err %d", ret); 540 PDEBUG(D_ERR, "reg_read err %d", ret);
541 return -1; 541 return -1;
542 } 542 }
543 return (buf[1] << 8) + buf[0]; 543 return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0];
544} 544}
545 545
546static int write_vector(struct gspca_dev *gspca_dev, 546static int write_vector(struct gspca_dev *gspca_dev,
@@ -550,7 +550,7 @@ static int write_vector(struct gspca_dev *gspca_dev,
550 int ret, i = 0; 550 int ret, i = 0;
551 551
552 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) { 552 while (data[i][0] != 0 || data[i][1] != 0 || data[i][2] != 0) {
553 ret = reg_write(dev, data[i][0], data[i][2], data[i][1]); 553 ret = reg_w_riv(dev, data[i][0], data[i][2], data[i][1]);
554 if (ret < 0) { 554 if (ret < 0) {
555 PDEBUG(D_ERR, 555 PDEBUG(D_ERR,
556 "Register write failed for 0x%x,0x%x,0x%x", 556 "Register write failed for 0x%x,0x%x,0x%x",
@@ -573,14 +573,14 @@ static int spca50x_setup_qtable(struct gspca_dev *gspca_dev,
573 573
574 /* loop over y components */ 574 /* loop over y components */
575 for (i = 0; i < 64; i++) { 575 for (i = 0; i < 64; i++) {
576 err = reg_write(dev, request, ybase + i, qtable[0][i]); 576 err = reg_w_riv(dev, request, ybase + i, qtable[0][i]);
577 if (err < 0) 577 if (err < 0)
578 return err; 578 return err;
579 } 579 }
580 580
581 /* loop over c components */ 581 /* loop over c components */
582 for (i = 0; i < 64; i++) { 582 for (i = 0; i < 64; i++) {
583 err = reg_write(dev, request, cbase + i, qtable[1][i]); 583 err = reg_w_riv(dev, request, cbase + i, qtable[1][i]);
584 if (err < 0) 584 if (err < 0)
585 return err; 585 return err;
586 } 586 }
@@ -593,14 +593,14 @@ static void spca504_acknowledged_command(struct gspca_dev *gspca_dev,
593 struct usb_device *dev = gspca_dev->dev; 593 struct usb_device *dev = gspca_dev->dev;
594 __u8 notdone; 594 __u8 notdone;
595 595
596 reg_write(dev, req, idx, val); 596 reg_w_riv(dev, req, idx, val);
597 notdone = reg_read(dev, 0x01, 0x0001, 1); 597 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
598 reg_write(dev, req, idx, val); 598 reg_w_riv(dev, req, idx, val);
599 599
600 PDEBUG(D_FRAM, "before wait 0x%x", notdone); 600 PDEBUG(D_FRAM, "before wait 0x%x", notdone);
601 601
602 msleep(200); 602 msleep(200);
603 notdone = reg_read(dev, 0x01, 0x0001, 1); 603 notdone = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
604 PDEBUG(D_FRAM, "after wait 0x%x", notdone); 604 PDEBUG(D_FRAM, "after wait 0x%x", notdone);
605} 605}
606 606
@@ -612,8 +612,8 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
612 __u8 status; 612 __u8 status;
613 __u8 endcode; 613 __u8 endcode;
614 614
615 reg_write(dev, req, idx, val); 615 reg_w_riv(dev, req, idx, val);
616 status = reg_read(dev, 0x01, 0x0001, 1); 616 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
617 endcode = stat; 617 endcode = stat;
618 PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat); 618 PDEBUG(D_FRAM, "Status 0x%x Need 0x%x", status, stat);
619 if (!count) 619 if (!count)
@@ -622,8 +622,8 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
622 while (--count > 0) { 622 while (--count > 0) {
623 msleep(10); 623 msleep(10);
624 /* gsmart mini2 write a each wait setting 1 ms is enought */ 624 /* gsmart mini2 write a each wait setting 1 ms is enought */
625/* reg_write(dev, req, idx, val); */ 625/* reg_w_riv(dev, req, idx, val); */
626 status = reg_read(dev, 0x01, 0x0001, 1); 626 status = reg_r_12(gspca_dev, 0x01, 0x0001, 1);
627 if (status == endcode) { 627 if (status == endcode) {
628 PDEBUG(D_FRAM, "status 0x%x after wait 0x%x", 628 PDEBUG(D_FRAM, "status 0x%x after wait 0x%x",
629 status, 200 - count); 629 status, 200 - count);
@@ -632,34 +632,31 @@ static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev,
632 } 632 }
633} 633}
634 634
635static int spca504B_PollingDataReady(struct usb_device *dev) 635static int spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
636{ 636{
637 __u8 DataReady;
638 int count = 10; 637 int count = 10;
639 638
640 while (--count > 0) { 639 while (--count > 0) {
641 spca5xxRegRead(dev, 0x21, 0, &DataReady, 1); 640 reg_r(gspca_dev->dev, 0x21, 0, gspca_dev->usb_buf, 1);
642 if ((DataReady & 0x01) == 0) 641 if ((gspca_dev->usb_buf[0] & 0x01) == 0)
643 break; 642 break;
644 msleep(10); 643 msleep(10);
645 } 644 }
646 return DataReady; 645 return gspca_dev->usb_buf[0];
647} 646}
648 647
649static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev) 648static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
650{ 649{
651 struct usb_device *dev = gspca_dev->dev; 650 struct usb_device *dev = gspca_dev->dev;
652 __u8 DataReady;
653 int count = 50; 651 int count = 50;
654 652
655 while (--count > 0) { 653 while (--count > 0) {
656 spca5xxRegRead(dev, 0x21, 1, &DataReady, 1); 654 reg_r(dev, 0x21, 1, gspca_dev->usb_buf, 1);
657 655 if (gspca_dev->usb_buf[0] != 0) {
658 if (DataReady) { 656 gspca_dev->usb_buf[0] = 0;
659 DataReady = 0; 657 reg_w(dev, 0x21, 0, 1, gspca_dev->usb_buf, 1);
660 spca5xxRegWrite(dev, 0x21, 0, 1, &DataReady, 1); 658 reg_r(dev, 0x21, 1, gspca_dev->usb_buf, 1);
661 spca5xxRegRead(dev, 0x21, 1, &DataReady, 1); 659 spca504B_PollingDataReady(gspca_dev);
662 spca504B_PollingDataReady(dev);
663 break; 660 break;
664 } 661 }
665 msleep(10); 662 msleep(10);
@@ -669,14 +666,15 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
669static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) 666static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
670{ 667{
671 struct usb_device *dev = gspca_dev->dev; 668 struct usb_device *dev = gspca_dev->dev;
672 __u8 FW[5]; 669 __u8 *data;
673 __u8 ProductInfo[64];
674 670
675 spca5xxRegRead(dev, 0x20, 0, FW, 5); 671 data = kmalloc(64, GFP_KERNEL);
672 reg_r(dev, 0x20, 0, data, 5);
676 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ", 673 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
677 FW[0], FW[1], FW[2], FW[3], FW[4]); 674 data[0], data[1], data[2], data[3], data[4]);
678 spca5xxRegRead(dev, 0x23, 0, ProductInfo, 64); 675 reg_r(dev, 0x23, 0, data, 64);
679 spca5xxRegRead(dev, 0x23, 1, ProductInfo, 64); 676 reg_r(dev, 0x23, 1, data, 64);
677 kfree(data);
680} 678}
681 679
682static void spca504B_SetSizeType(struct gspca_dev *gspca_dev) 680static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
@@ -691,32 +689,35 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
691 Type = 0; 689 Type = 0;
692 switch (sd->bridge) { 690 switch (sd->bridge) {
693 case BRIDGE_SPCA533: 691 case BRIDGE_SPCA533:
694 spca5xxRegWrite(dev, 0x31, 0, 0, NULL, 0); 692 reg_w(dev, 0x31, 0, 0, NULL, 0);
695 spca504B_WaitCmdStatus(gspca_dev); 693 spca504B_WaitCmdStatus(gspca_dev);
696 rc = spca504B_PollingDataReady(dev); 694 rc = spca504B_PollingDataReady(gspca_dev);
697 spca50x_GetFirmware(gspca_dev); 695 spca50x_GetFirmware(gspca_dev);
698 Type = 2; 696 gspca_dev->usb_buf[0] = 2; /* type */
699 spca5xxRegWrite(dev, 0x24, 0, 8, &Type, 1); 697 reg_w(dev, 0x24, 0, 8, gspca_dev->usb_buf, 1);
700 spca5xxRegRead(dev, 0x24, 8, &Type, 1); 698 reg_r(dev, 0x24, 8, gspca_dev->usb_buf, 1);
701 699
702 spca5xxRegWrite(dev, 0x25, 0, 4, &Size, 1); 700 gspca_dev->usb_buf[0] = Size;
703 spca5xxRegRead(dev, 0x25, 4, &Size, 1); 701 reg_w(dev, 0x25, 0, 4, gspca_dev->usb_buf, 1);
704 rc = spca504B_PollingDataReady(dev); 702 reg_r(dev, 0x25, 4, gspca_dev->usb_buf, 1); /* size */
703 rc = spca504B_PollingDataReady(gspca_dev);
705 704
706 /* Init the cam width height with some values get on init ? */ 705 /* Init the cam width height with some values get on init ? */
707 spca5xxRegWrite(dev, 0x31, 0, 4, NULL, 0); 706 reg_w(dev, 0x31, 0, 4, NULL, 0);
708 spca504B_WaitCmdStatus(gspca_dev); 707 spca504B_WaitCmdStatus(gspca_dev);
709 rc = spca504B_PollingDataReady(dev); 708 rc = spca504B_PollingDataReady(gspca_dev);
710 break; 709 break;
711 default: 710 default:
712/* case BRIDGE_SPCA504B: */ 711/* case BRIDGE_SPCA504B: */
713/* case BRIDGE_SPCA536: */ 712/* case BRIDGE_SPCA536: */
713 gspca_dev->usb_buf[0] = Size;
714 reg_w(dev, 0x25, 0, 4, gspca_dev->usb_buf, 1);
715 reg_r(dev, 0x25, 4, gspca_dev->usb_buf, 1); /* size */
714 Type = 6; 716 Type = 6;
715 spca5xxRegWrite(dev, 0x25, 0, 4, &Size, 1); 717 gspca_dev->usb_buf[0] = Type;
716 spca5xxRegRead(dev, 0x25, 4, &Size, 1); 718 reg_w(dev, 0x27, 0, 0, gspca_dev->usb_buf, 1);
717 spca5xxRegWrite(dev, 0x27, 0, 0, &Type, 1); 719 reg_r(dev, 0x27, 0, gspca_dev->usb_buf, 1); /* type */
718 spca5xxRegRead(dev, 0x27, 0, &Type, 1); 720 rc = spca504B_PollingDataReady(gspca_dev);
719 rc = spca504B_PollingDataReady(dev);
720 break; 721 break;
721 case BRIDGE_SPCA504: 722 case BRIDGE_SPCA504:
722 Size += 3; 723 Size += 3;
@@ -733,21 +734,20 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
733 break; 734 break;
734 case BRIDGE_SPCA504C: 735 case BRIDGE_SPCA504C:
735 /* capture mode */ 736 /* capture mode */
736 reg_write(dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x0); 737 reg_w_riv(dev, 0xa0, (0x0500 | (Size & 0x0f)), 0x00);
737 reg_write(dev, 0x20, 0x01, 0x0500 | (Size & 0x0f)); 738 reg_w_riv(dev, 0x20, 0x01, 0x0500 | (Size & 0x0f));
738 break; 739 break;
739 } 740 }
740} 741}
741 742
742static void spca504_wait_status(struct gspca_dev *gspca_dev) 743static void spca504_wait_status(struct gspca_dev *gspca_dev)
743{ 744{
744 struct usb_device *dev = gspca_dev->dev;
745 int cnt; 745 int cnt;
746 746
747 cnt = 256; 747 cnt = 256;
748 while (--cnt > 0) { 748 while (--cnt > 0) {
749 /* With this we get the status, when return 0 it's all ok */ 749 /* With this we get the status, when return 0 it's all ok */
750 if (reg_read(dev, 0x06, 0x00, 1) == 0) 750 if (reg_r_12(gspca_dev, 0x06, 0x00, 1) == 0)
751 return; 751 return;
752 msleep(10); 752 msleep(10);
753 } 753 }
@@ -756,11 +756,11 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev)
756static void spca504B_setQtable(struct gspca_dev *gspca_dev) 756static void spca504B_setQtable(struct gspca_dev *gspca_dev)
757{ 757{
758 struct usb_device *dev = gspca_dev->dev; 758 struct usb_device *dev = gspca_dev->dev;
759 __u8 Data = 3;
760 759
761 spca5xxRegWrite(dev, 0x26, 0, 0, &Data, 1); 760 gspca_dev->usb_buf[0] = 3;
762 spca5xxRegRead(dev, 0x26, 0, &Data, 1); 761 reg_w(dev, 0x26, 0, 0, gspca_dev->usb_buf, 1);
763 spca504B_PollingDataReady(dev); 762 reg_r(dev, 0x26, 0, gspca_dev->usb_buf, 1);
763 spca504B_PollingDataReady(gspca_dev);
764} 764}
765 765
766static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev) 766static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
@@ -777,24 +777,24 @@ static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
777 default: 777 default:
778/* case BRIDGE_SPCA533: */ 778/* case BRIDGE_SPCA533: */
779/* case BRIDGE_SPCA504B: */ 779/* case BRIDGE_SPCA504B: */
780 spca5xxRegWrite(dev, 0, 0, 0x21a7, NULL, 0); /* brightness */ 780 reg_w(dev, 0, 0, 0x21a7, NULL, 0); /* brightness */
781 spca5xxRegWrite(dev, 0, 0x20, 0x21a8, NULL, 0); /* contrast */ 781 reg_w(dev, 0, 0x20, 0x21a8, NULL, 0); /* contrast */
782 spca5xxRegWrite(dev, 0, 0, 0x21ad, NULL, 0); /* hue */ 782 reg_w(dev, 0, 0, 0x21ad, NULL, 0); /* hue */
783 spca5xxRegWrite(dev, 0, 1, 0x21ac, NULL, 0); /* sat/hue */ 783 reg_w(dev, 0, 1, 0x21ac, NULL, 0); /* sat/hue */
784 spca5xxRegWrite(dev, 0, 0x20, 0x21ae, NULL, 0); /* saturation */ 784 reg_w(dev, 0, 0x20, 0x21ae, NULL, 0); /* saturation */
785 spca5xxRegWrite(dev, 0, 0, 0x21a3, NULL, 0); /* gamma */ 785 reg_w(dev, 0, 0, 0x21a3, NULL, 0); /* gamma */
786 break; 786 break;
787 case BRIDGE_SPCA536: 787 case BRIDGE_SPCA536:
788 spca5xxRegWrite(dev, 0, 0, 0x20f0, NULL, 0); 788 reg_w(dev, 0, 0, 0x20f0, NULL, 0);
789 spca5xxRegWrite(dev, 0, 0x21, 0x20f1, NULL, 0); 789 reg_w(dev, 0, 0x21, 0x20f1, NULL, 0);
790 spca5xxRegWrite(dev, 0, 0x40, 0x20f5, NULL, 0); 790 reg_w(dev, 0, 0x40, 0x20f5, NULL, 0);
791 spca5xxRegWrite(dev, 0, 1, 0x20f4, NULL, 0); 791 reg_w(dev, 0, 1, 0x20f4, NULL, 0);
792 spca5xxRegWrite(dev, 0, 0x40, 0x20f6, NULL, 0); 792 reg_w(dev, 0, 0x40, 0x20f6, NULL, 0);
793 spca5xxRegWrite(dev, 0, 0, 0x2089, NULL, 0); 793 reg_w(dev, 0, 0, 0x2089, NULL, 0);
794 break; 794 break;
795 } 795 }
796 if (pollreg) 796 if (pollreg)
797 spca504B_PollingDataReady(dev); 797 spca504B_PollingDataReady(gspca_dev);
798} 798}
799 799
800/* this function is called at probe time */ 800/* this function is called at probe time */
@@ -872,7 +872,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
872 case 0x504a: 872 case 0x504a:
873/* try to get the firmware as some cam answer 2.0.1.2.2 873/* try to get the firmware as some cam answer 2.0.1.2.2
874 * and should be a spca504b then overwrite that setting */ 874 * and should be a spca504b then overwrite that setting */
875 spca5xxRegRead(dev, 0x20, 0, &fw, 1); 875 reg_r(dev, 0x20, 0, gspca_dev->usb_buf, 1);
876 fw = gspca_dev->usb_buf[0];
876 if (fw == 1) { 877 if (fw == 1) {
877 sd->subtype = AiptekMiniPenCam13; 878 sd->subtype = AiptekMiniPenCam13;
878 sd->bridge = BRIDGE_SPCA504; 879 sd->bridge = BRIDGE_SPCA504;
@@ -1048,38 +1049,37 @@ static int sd_open(struct gspca_dev *gspca_dev)
1048 struct sd *sd = (struct sd *) gspca_dev; 1049 struct sd *sd = (struct sd *) gspca_dev;
1049 struct usb_device *dev = gspca_dev->dev; 1050 struct usb_device *dev = gspca_dev->dev;
1050 int rc; 1051 int rc;
1051 __u8 Data;
1052 __u8 i; 1052 __u8 i;
1053 __u8 info[6]; 1053 __u8 info[6];
1054 int err_code; 1054 int err_code;
1055 1055
1056 switch (sd->bridge) { 1056 switch (sd->bridge) {
1057 case BRIDGE_SPCA504B: 1057 case BRIDGE_SPCA504B:
1058 spca5xxRegWrite(dev, 0x1d, 0, 0, NULL, 0); 1058 reg_w(dev, 0x1d, 0, 0, NULL, 0);
1059 spca5xxRegWrite(dev, 0, 1, 0x2306, NULL, 0); 1059 reg_w(dev, 0, 1, 0x2306, NULL, 0);
1060 spca5xxRegWrite(dev, 0, 0, 0x0d04, NULL, 0); 1060 reg_w(dev, 0, 0, 0x0d04, NULL, 0);
1061 spca5xxRegWrite(dev, 0, 0, 0x2000, NULL, 0); 1061 reg_w(dev, 0, 0, 0x2000, NULL, 0);
1062 spca5xxRegWrite(dev, 0, 0x13, 0x2301, NULL, 0); 1062 reg_w(dev, 0, 0x13, 0x2301, NULL, 0);
1063 spca5xxRegWrite(dev, 0, 0, 0x2306, NULL, 0); 1063 reg_w(dev, 0, 0, 0x2306, NULL, 0);
1064 /* fall thru */ 1064 /* fall thru */
1065 case BRIDGE_SPCA533: 1065 case BRIDGE_SPCA533:
1066 rc = spca504B_PollingDataReady(dev); 1066 rc = spca504B_PollingDataReady(gspca_dev);
1067 spca50x_GetFirmware(gspca_dev); 1067 spca50x_GetFirmware(gspca_dev);
1068 break; 1068 break;
1069 case BRIDGE_SPCA536: 1069 case BRIDGE_SPCA536:
1070 spca50x_GetFirmware(gspca_dev); 1070 spca50x_GetFirmware(gspca_dev);
1071 spca5xxRegRead(dev, 0x00, 0x5002, &Data, 1); 1071 reg_r(dev, 0x00, 0x5002, gspca_dev->usb_buf, 1);
1072 Data = 0; 1072 gspca_dev->usb_buf[0] = 0;
1073 spca5xxRegWrite(dev, 0x24, 0, 0, &Data, 1); 1073 reg_w(dev, 0x24, 0, 0, gspca_dev->usb_buf, 1);
1074 spca5xxRegRead(dev, 0x24, 0, &Data, 1); 1074 reg_r(dev, 0x24, 0, gspca_dev->usb_buf, 1);
1075 rc = spca504B_PollingDataReady(dev); 1075 rc = spca504B_PollingDataReady(gspca_dev);
1076 spca5xxRegWrite(dev, 0x34, 0, 0, NULL, 0); 1076 reg_w(dev, 0x34, 0, 0, NULL, 0);
1077 spca504B_WaitCmdStatus(gspca_dev); 1077 spca504B_WaitCmdStatus(gspca_dev);
1078 break; 1078 break;
1079 case BRIDGE_SPCA504C: /* pccam600 */ 1079 case BRIDGE_SPCA504C: /* pccam600 */
1080 PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)"); 1080 PDEBUG(D_STREAM, "Opening SPCA504 (PC-CAM 600)");
1081 reg_write(dev, 0xe0, 0x0000, 0x0000); 1081 reg_w_riv(dev, 0xe0, 0x0000, 0x0000);
1082 reg_write(dev, 0xe0, 0x0000, 0x0001); /* reset */ 1082 reg_w_riv(dev, 0xe0, 0x0000, 0x0001); /* reset */
1083 spca504_wait_status(gspca_dev); 1083 spca504_wait_status(gspca_dev);
1084 if (sd->subtype == LogitechClickSmart420) 1084 if (sd->subtype == LogitechClickSmart420)
1085 write_vector(gspca_dev, 1085 write_vector(gspca_dev,
@@ -1100,7 +1100,7 @@ static int sd_open(struct gspca_dev *gspca_dev)
1100 if (sd->subtype == AiptekMiniPenCam13) { 1100 if (sd->subtype == AiptekMiniPenCam13) {
1101 /*****************************/ 1101 /*****************************/
1102 for (i = 0; i < 6; i++) 1102 for (i = 0; i < 6; i++)
1103 info[i] = reg_read_info(dev, i); 1103 info[i] = reg_r_1(gspca_dev, i);
1104 PDEBUG(D_STREAM, 1104 PDEBUG(D_STREAM,
1105 "Read info: %d %d %d %d %d %d." 1105 "Read info: %d %d %d %d %d %d."
1106 " Should be 1,0,2,2,0,0", 1106 " Should be 1,0,2,2,0,0",
@@ -1126,14 +1126,14 @@ static int sd_open(struct gspca_dev *gspca_dev)
1126 6, 0, 0x86, 1); */ 1126 6, 0, 0x86, 1); */
1127/* spca504A_acknowledged_command (gspca_dev, 0x24, 1127/* spca504A_acknowledged_command (gspca_dev, 0x24,
1128 0, 0, 0x9D, 1); */ 1128 0, 0, 0x9D, 1); */
1129 reg_write(dev, 0x0, 0x270c, 0x5); /* L92 sno1t.txt */ 1129 reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
1130 reg_write(dev, 0x0, 0x2310, 0x5); 1130 reg_w_riv(dev, 0x0, 0x2310, 0x05);
1131 spca504A_acknowledged_command(gspca_dev, 0x01, 1131 spca504A_acknowledged_command(gspca_dev, 0x01,
1132 0x0f, 0, 0xff, 0); 1132 0x0f, 0, 0xff, 0);
1133 } 1133 }
1134 /* setup qtable */ 1134 /* setup qtable */
1135 reg_write(dev, 0, 0x2000, 0); 1135 reg_w_riv(dev, 0, 0x2000, 0);
1136 reg_write(dev, 0, 0x2883, 1); 1136 reg_w_riv(dev, 0, 0x2883, 1);
1137 err_code = spca50x_setup_qtable(gspca_dev, 1137 err_code = spca50x_setup_qtable(gspca_dev,
1138 0x00, 0x2800, 1138 0x00, 0x2800,
1139 0x2840, 1139 0x2840,
@@ -1166,20 +1166,20 @@ static void sd_start(struct gspca_dev *gspca_dev)
1166/* case BRIDGE_SPCA536: */ 1166/* case BRIDGE_SPCA536: */
1167 if (sd->subtype == MegapixV4 || 1167 if (sd->subtype == MegapixV4 ||
1168 sd->subtype == LogitechClickSmart820) { 1168 sd->subtype == LogitechClickSmart820) {
1169 spca5xxRegWrite(dev, 0xf0, 0, 0, NULL, 0); 1169 reg_w(dev, 0xf0, 0, 0, NULL, 0);
1170 spca504B_WaitCmdStatus(gspca_dev); 1170 spca504B_WaitCmdStatus(gspca_dev);
1171 spca5xxRegRead(dev, 0xf0, 4, NULL, 0); 1171 reg_r(dev, 0xf0, 4, NULL, 0);
1172 spca504B_WaitCmdStatus(gspca_dev); 1172 spca504B_WaitCmdStatus(gspca_dev);
1173 } else { 1173 } else {
1174 spca5xxRegWrite(dev, 0x31, 0, 4, NULL, 0); 1174 reg_w(dev, 0x31, 0, 4, NULL, 0);
1175 spca504B_WaitCmdStatus(gspca_dev); 1175 spca504B_WaitCmdStatus(gspca_dev);
1176 rc = spca504B_PollingDataReady(dev); 1176 rc = spca504B_PollingDataReady(gspca_dev);
1177 } 1177 }
1178 break; 1178 break;
1179 case BRIDGE_SPCA504: 1179 case BRIDGE_SPCA504:
1180 if (sd->subtype == AiptekMiniPenCam13) { 1180 if (sd->subtype == AiptekMiniPenCam13) {
1181 for (i = 0; i < 6; i++) 1181 for (i = 0; i < 6; i++)
1182 info[i] = reg_read_info(dev, i); 1182 info[i] = reg_r_1(gspca_dev, i);
1183 PDEBUG(D_STREAM, 1183 PDEBUG(D_STREAM,
1184 "Read info: %d %d %d %d %d %d." 1184 "Read info: %d %d %d %d %d %d."
1185 " Should be 1,0,2,2,0,0", 1185 " Should be 1,0,2,2,0,0",
@@ -1197,7 +1197,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1197 } else { 1197 } else {
1198 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); 1198 spca504_acknowledged_command(gspca_dev, 0x24, 8, 3);
1199 for (i = 0; i < 6; i++) 1199 for (i = 0; i < 6; i++)
1200 info[i] = reg_read_info(dev, i); 1200 info[i] = reg_r_1(gspca_dev, i);
1201 PDEBUG(D_STREAM, 1201 PDEBUG(D_STREAM,
1202 "Read info: %d %d %d %d %d %d." 1202 "Read info: %d %d %d %d %d %d."
1203 " Should be 1,0,2,2,0,0", 1203 " Should be 1,0,2,2,0,0",
@@ -1207,8 +1207,8 @@ static void sd_start(struct gspca_dev *gspca_dev)
1207 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 1207 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1208 } 1208 }
1209 spca504B_SetSizeType(gspca_dev); 1209 spca504B_SetSizeType(gspca_dev);
1210 reg_write(dev, 0x0, 0x270c, 0x5); /* L92 sno1t.txt */ 1210 reg_w_riv(dev, 0x0, 0x270c, 0x05); /* L92 sno1t.txt */
1211 reg_write(dev, 0x0, 0x2310, 0x5); 1211 reg_w_riv(dev, 0x0, 0x2310, 0x05);
1212 break; 1212 break;
1213 case BRIDGE_SPCA504C: 1213 case BRIDGE_SPCA504C:
1214 if (sd->subtype == LogitechClickSmart420) { 1214 if (sd->subtype == LogitechClickSmart420) {
@@ -1217,13 +1217,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
1217 } else { 1217 } else {
1218 write_vector(gspca_dev, spca504_pccam600_init_data); 1218 write_vector(gspca_dev, spca504_pccam600_init_data);
1219 } 1219 }
1220 enable = (sd->autogain ? 0x4 : 0x1); 1220 enable = (sd->autogain ? 0x04 : 0x01);
1221 reg_write(dev, 0x0c, 0x0000, enable); /* auto exposure */ 1221 reg_w_riv(dev, 0x0c, 0x0000, enable); /* auto exposure */
1222 reg_write(dev, 0xb0, 0x0000, enable); /* auto whiteness */ 1222 reg_w_riv(dev, 0xb0, 0x0000, enable); /* auto whiteness */
1223 1223
1224 /* set default exposure compensation and whiteness balance */ 1224 /* set default exposure compensation and whiteness balance */
1225 reg_write(dev, 0x30, 0x0001, 800); /* ~ 20 fps */ 1225 reg_w_riv(dev, 0x30, 0x0001, 800); /* ~ 20 fps */
1226 reg_write(dev, 0x30, 0x0002, 1600); 1226 reg_w_riv(dev, 0x30, 0x0002, 1600);
1227 spca504B_SetSizeType(gspca_dev); 1227 spca504B_SetSizeType(gspca_dev);
1228 break; 1228 break;
1229 } 1229 }
@@ -1240,13 +1240,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1240/* case BRIDGE_SPCA533: */ 1240/* case BRIDGE_SPCA533: */
1241/* case BRIDGE_SPCA536: */ 1241/* case BRIDGE_SPCA536: */
1242/* case BRIDGE_SPCA504B: */ 1242/* case BRIDGE_SPCA504B: */
1243 spca5xxRegWrite(dev, 0x31, 0, 0, NULL, 0); 1243 reg_w(dev, 0x31, 0, 0, NULL, 0);
1244 spca504B_WaitCmdStatus(gspca_dev); 1244 spca504B_WaitCmdStatus(gspca_dev);
1245 spca504B_PollingDataReady(dev); 1245 spca504B_PollingDataReady(gspca_dev);
1246 break; 1246 break;
1247 case BRIDGE_SPCA504: 1247 case BRIDGE_SPCA504:
1248 case BRIDGE_SPCA504C: 1248 case BRIDGE_SPCA504C:
1249 reg_write(dev, 0x00, 0x2000, 0x0000); 1249 reg_w_riv(dev, 0x00, 0x2000, 0x0000);
1250 1250
1251 if (sd->subtype == AiptekMiniPenCam13) { 1251 if (sd->subtype == AiptekMiniPenCam13) {
1252 /* spca504a aiptek */ 1252 /* spca504a aiptek */
@@ -1258,7 +1258,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1258 0x0f, 0x00, 0xff, 1); 1258 0x0f, 0x00, 0xff, 1);
1259 } else { 1259 } else {
1260 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); 1260 spca504_acknowledged_command(gspca_dev, 0x24, 0, 0);
1261 reg_write(dev, 0x01, 0x000f, 0x0); 1261 reg_w_riv(dev, 0x01, 0x000f, 0x00);
1262 } 1262 }
1263 break; 1263 break;
1264 } 1264 }
@@ -1383,10 +1383,10 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1383/* case BRIDGE_SPCA504B: */ 1383/* case BRIDGE_SPCA504B: */
1384/* case BRIDGE_SPCA504: */ 1384/* case BRIDGE_SPCA504: */
1385/* case BRIDGE_SPCA504C: */ 1385/* case BRIDGE_SPCA504C: */
1386 reg_write(dev, 0x0, 0x21a7, sd->brightness); 1386 reg_w_riv(dev, 0x0, 0x21a7, sd->brightness);
1387 break; 1387 break;
1388 case BRIDGE_SPCA536: 1388 case BRIDGE_SPCA536:
1389 reg_write(dev, 0x0, 0x20f0, sd->brightness); 1389 reg_w_riv(dev, 0x0, 0x20f0, sd->brightness);
1390 break; 1390 break;
1391 } 1391 }
1392} 1392}
@@ -1394,7 +1394,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1394static void getbrightness(struct gspca_dev *gspca_dev) 1394static void getbrightness(struct gspca_dev *gspca_dev)
1395{ 1395{
1396 struct sd *sd = (struct sd *) gspca_dev; 1396 struct sd *sd = (struct sd *) gspca_dev;
1397 struct usb_device *dev = gspca_dev->dev;
1398 __u16 brightness = 0; 1397 __u16 brightness = 0;
1399 1398
1400 switch (sd->bridge) { 1399 switch (sd->bridge) {
@@ -1403,10 +1402,10 @@ static void getbrightness(struct gspca_dev *gspca_dev)
1403/* case BRIDGE_SPCA504B: */ 1402/* case BRIDGE_SPCA504B: */
1404/* case BRIDGE_SPCA504: */ 1403/* case BRIDGE_SPCA504: */
1405/* case BRIDGE_SPCA504C: */ 1404/* case BRIDGE_SPCA504C: */
1406 brightness = reg_read(dev, 0x0, 0x21a7, 2); 1405 brightness = reg_r_12(gspca_dev, 0x00, 0x21a7, 2);
1407 break; 1406 break;
1408 case BRIDGE_SPCA536: 1407 case BRIDGE_SPCA536:
1409 brightness = reg_read(dev, 0x0, 0x20f0, 2); 1408 brightness = reg_r_12(gspca_dev, 0x00, 0x20f0, 2);
1410 break; 1409 break;
1411 } 1410 }
1412 sd->brightness = ((brightness & 0xff) - 128) % 255; 1411 sd->brightness = ((brightness & 0xff) - 128) % 255;
@@ -1423,10 +1422,10 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1423/* case BRIDGE_SPCA504B: */ 1422/* case BRIDGE_SPCA504B: */
1424/* case BRIDGE_SPCA504: */ 1423/* case BRIDGE_SPCA504: */
1425/* case BRIDGE_SPCA504C: */ 1424/* case BRIDGE_SPCA504C: */
1426 reg_write(dev, 0x0, 0x21a8, sd->contrast); 1425 reg_w_riv(dev, 0x0, 0x21a8, sd->contrast);
1427 break; 1426 break;
1428 case BRIDGE_SPCA536: 1427 case BRIDGE_SPCA536:
1429 reg_write(dev, 0x0, 0x20f1, sd->contrast); 1428 reg_w_riv(dev, 0x0, 0x20f1, sd->contrast);
1430 break; 1429 break;
1431 } 1430 }
1432} 1431}
@@ -1434,7 +1433,6 @@ static void setcontrast(struct gspca_dev *gspca_dev)
1434static void getcontrast(struct gspca_dev *gspca_dev) 1433static void getcontrast(struct gspca_dev *gspca_dev)
1435{ 1434{
1436 struct sd *sd = (struct sd *) gspca_dev; 1435 struct sd *sd = (struct sd *) gspca_dev;
1437 struct usb_device *dev = gspca_dev->dev;
1438 1436
1439 switch (sd->bridge) { 1437 switch (sd->bridge) {
1440 default: 1438 default:
@@ -1442,10 +1440,10 @@ static void getcontrast(struct gspca_dev *gspca_dev)
1442/* case BRIDGE_SPCA504B: */ 1440/* case BRIDGE_SPCA504B: */
1443/* case BRIDGE_SPCA504: */ 1441/* case BRIDGE_SPCA504: */
1444/* case BRIDGE_SPCA504C: */ 1442/* case BRIDGE_SPCA504C: */
1445 sd->contrast = reg_read(dev, 0x0, 0x21a8, 2); 1443 sd->contrast = reg_r_12(gspca_dev, 0x00, 0x21a8, 2);
1446 break; 1444 break;
1447 case BRIDGE_SPCA536: 1445 case BRIDGE_SPCA536:
1448 sd->contrast = reg_read(dev, 0x0, 0x20f1, 2); 1446 sd->contrast = reg_r_12(gspca_dev, 0x00, 0x20f1, 2);
1449 break; 1447 break;
1450 } 1448 }
1451} 1449}
@@ -1461,10 +1459,10 @@ static void setcolors(struct gspca_dev *gspca_dev)
1461/* case BRIDGE_SPCA504B: */ 1459/* case BRIDGE_SPCA504B: */
1462/* case BRIDGE_SPCA504: */ 1460/* case BRIDGE_SPCA504: */
1463/* case BRIDGE_SPCA504C: */ 1461/* case BRIDGE_SPCA504C: */
1464 reg_write(dev, 0x0, 0x21ae, sd->colors); 1462 reg_w_riv(dev, 0x0, 0x21ae, sd->colors);
1465 break; 1463 break;
1466 case BRIDGE_SPCA536: 1464 case BRIDGE_SPCA536:
1467 reg_write(dev, 0x0, 0x20f6, sd->colors); 1465 reg_w_riv(dev, 0x0, 0x20f6, sd->colors);
1468 break; 1466 break;
1469 } 1467 }
1470} 1468}
@@ -1472,7 +1470,6 @@ static void setcolors(struct gspca_dev *gspca_dev)
1472static void getcolors(struct gspca_dev *gspca_dev) 1470static void getcolors(struct gspca_dev *gspca_dev)
1473{ 1471{
1474 struct sd *sd = (struct sd *) gspca_dev; 1472 struct sd *sd = (struct sd *) gspca_dev;
1475 struct usb_device *dev = gspca_dev->dev;
1476 1473
1477 switch (sd->bridge) { 1474 switch (sd->bridge) {
1478 default: 1475 default:
@@ -1480,10 +1477,10 @@ static void getcolors(struct gspca_dev *gspca_dev)
1480/* case BRIDGE_SPCA504B: */ 1477/* case BRIDGE_SPCA504B: */
1481/* case BRIDGE_SPCA504: */ 1478/* case BRIDGE_SPCA504: */
1482/* case BRIDGE_SPCA504C: */ 1479/* case BRIDGE_SPCA504C: */
1483 sd->colors = reg_read(dev, 0x0, 0x21ae, 2) >> 1; 1480 sd->colors = reg_r_12(gspca_dev, 0x00, 0x21ae, 2) >> 1;
1484 break; 1481 break;
1485 case BRIDGE_SPCA536: 1482 case BRIDGE_SPCA536:
1486 sd->colors = reg_read(dev, 0x0, 0x20f6, 2) >> 1; 1483 sd->colors = reg_r_12(gspca_dev, 0x00, 0x20f6, 2) >> 1;
1487 break; 1484 break;
1488 } 1485 }
1489} 1486}