aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/gspca/sunplus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/gspca/sunplus.c')
-rw-r--r--drivers/media/video/gspca/sunplus.c167
1 files changed, 85 insertions, 82 deletions
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 54efa48bee01..1cfcc6c49558 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -449,31 +449,47 @@ static const __u8 qtable_spca504_default[2][64] = {
449 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e} 449 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e}
450}; 450};
451 451
452static void reg_r(struct usb_device *dev, 452/* read <len> bytes to gspca_dev->usb_buf */
453 __u16 req, 453static void reg_r(struct gspca_dev *gspca_dev,
454 __u16 index, 454 __u16 req,
455 __u8 *buffer, __u16 length) 455 __u16 index,
456 __u16 len)
456{ 457{
457 usb_control_msg(dev, 458#ifdef GSPCA_DEBUG
458 usb_rcvctrlpipe(dev, 0), 459 if (len > USB_BUF_SZ) {
460 err("reg_r: buffer overflow");
461 return;
462 }
463#endif
464 usb_control_msg(gspca_dev->dev,
465 usb_rcvctrlpipe(gspca_dev->dev, 0),
459 req, 466 req,
460 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 467 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
461 0, /* value */ 468 0, /* value */
462 index, buffer, length, 469 index,
470 len ? gspca_dev->usb_buf : NULL, len,
463 500); 471 500);
464} 472}
465 473
466static void reg_w(struct usb_device *dev, 474/* write <len> bytes from gspca_dev->usb_buf */
467 __u16 req, 475static void reg_w(struct gspca_dev *gspca_dev,
468 __u16 value, 476 __u16 req,
469 __u16 index, 477 __u16 value,
470 __u8 *buffer, __u16 length) 478 __u16 index,
479 __u16 len)
471{ 480{
472 usb_control_msg(dev, 481#ifdef GSPCA_DEBUG
473 usb_sndctrlpipe(dev, 0), 482 if (len > USB_BUF_SZ) {
483 err("reg_w: buffer overflow");
484 return;
485 }
486#endif
487 usb_control_msg(gspca_dev->dev,
488 usb_sndctrlpipe(gspca_dev->dev, 0),
474 req, 489 req,
475 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 490 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
476 value, index, buffer, length, 491 value, index,
492 len ? gspca_dev->usb_buf : NULL, len,
477 500); 493 500);
478} 494}
479 495
@@ -634,7 +650,7 @@ static int spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
634 int count = 10; 650 int count = 10;
635 651
636 while (--count > 0) { 652 while (--count > 0) {
637 reg_r(gspca_dev->dev, 0x21, 0, gspca_dev->usb_buf, 1); 653 reg_r(gspca_dev, 0x21, 0, 1);
638 if ((gspca_dev->usb_buf[0] & 0x01) == 0) 654 if ((gspca_dev->usb_buf[0] & 0x01) == 0)
639 break; 655 break;
640 msleep(10); 656 msleep(10);
@@ -644,15 +660,14 @@ static int spca504B_PollingDataReady(struct gspca_dev *gspca_dev)
644 660
645static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev) 661static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
646{ 662{
647 struct usb_device *dev = gspca_dev->dev;
648 int count = 50; 663 int count = 50;
649 664
650 while (--count > 0) { 665 while (--count > 0) {
651 reg_r(dev, 0x21, 1, gspca_dev->usb_buf, 1); 666 reg_r(gspca_dev, 0x21, 1, 1);
652 if (gspca_dev->usb_buf[0] != 0) { 667 if (gspca_dev->usb_buf[0] != 0) {
653 gspca_dev->usb_buf[0] = 0; 668 gspca_dev->usb_buf[0] = 0;
654 reg_w(dev, 0x21, 0, 1, gspca_dev->usb_buf, 1); 669 reg_w(gspca_dev, 0x21, 0, 1, 1);
655 reg_r(dev, 0x21, 1, gspca_dev->usb_buf, 1); 670 reg_r(gspca_dev, 0x21, 1, 1);
656 spca504B_PollingDataReady(gspca_dev); 671 spca504B_PollingDataReady(gspca_dev);
657 break; 672 break;
658 } 673 }
@@ -662,16 +677,14 @@ static void spca504B_WaitCmdStatus(struct gspca_dev *gspca_dev)
662 677
663static void spca50x_GetFirmware(struct gspca_dev *gspca_dev) 678static void spca50x_GetFirmware(struct gspca_dev *gspca_dev)
664{ 679{
665 struct usb_device *dev = gspca_dev->dev;
666 __u8 *data; 680 __u8 *data;
667 681
668 data = kmalloc(64, GFP_KERNEL); 682 data = gspca_dev->usb_buf;
669 reg_r(dev, 0x20, 0, data, 5); 683 reg_r(gspca_dev, 0x20, 0, 5);
670 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ", 684 PDEBUG(D_STREAM, "FirmWare : %d %d %d %d %d ",
671 data[0], data[1], data[2], data[3], data[4]); 685 data[0], data[1], data[2], data[3], data[4]);
672 reg_r(dev, 0x23, 0, data, 64); 686 reg_r(gspca_dev, 0x23, 0, 64);
673 reg_r(dev, 0x23, 1, data, 64); 687 reg_r(gspca_dev, 0x23, 1, 64);
674 kfree(data);
675} 688}
676 689
677static void spca504B_SetSizeType(struct gspca_dev *gspca_dev) 690static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
@@ -686,21 +699,21 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
686 Type = 0; 699 Type = 0;
687 switch (sd->bridge) { 700 switch (sd->bridge) {
688 case BRIDGE_SPCA533: 701 case BRIDGE_SPCA533:
689 reg_w(dev, 0x31, 0, 0, NULL, 0); 702 reg_w(gspca_dev, 0x31, 0, 0, 0);
690 spca504B_WaitCmdStatus(gspca_dev); 703 spca504B_WaitCmdStatus(gspca_dev);
691 rc = spca504B_PollingDataReady(gspca_dev); 704 rc = spca504B_PollingDataReady(gspca_dev);
692 spca50x_GetFirmware(gspca_dev); 705 spca50x_GetFirmware(gspca_dev);
693 gspca_dev->usb_buf[0] = 2; /* type */ 706 gspca_dev->usb_buf[0] = 2; /* type */
694 reg_w(dev, 0x24, 0, 8, gspca_dev->usb_buf, 1); 707 reg_w(gspca_dev, 0x24, 0, 8, 1);
695 reg_r(dev, 0x24, 8, gspca_dev->usb_buf, 1); 708 reg_r(gspca_dev, 0x24, 8, 1);
696 709
697 gspca_dev->usb_buf[0] = Size; 710 gspca_dev->usb_buf[0] = Size;
698 reg_w(dev, 0x25, 0, 4, gspca_dev->usb_buf, 1); 711 reg_w(gspca_dev, 0x25, 0, 4, 1);
699 reg_r(dev, 0x25, 4, gspca_dev->usb_buf, 1); /* size */ 712 reg_r(gspca_dev, 0x25, 4, 1); /* size */
700 rc = spca504B_PollingDataReady(gspca_dev); 713 rc = spca504B_PollingDataReady(gspca_dev);
701 714
702 /* Init the cam width height with some values get on init ? */ 715 /* Init the cam width height with some values get on init ? */
703 reg_w(dev, 0x31, 0, 4, NULL, 0); 716 reg_w(gspca_dev, 0x31, 0, 4, 0);
704 spca504B_WaitCmdStatus(gspca_dev); 717 spca504B_WaitCmdStatus(gspca_dev);
705 rc = spca504B_PollingDataReady(gspca_dev); 718 rc = spca504B_PollingDataReady(gspca_dev);
706 break; 719 break;
@@ -708,12 +721,12 @@ static void spca504B_SetSizeType(struct gspca_dev *gspca_dev)
708/* case BRIDGE_SPCA504B: */ 721/* case BRIDGE_SPCA504B: */
709/* case BRIDGE_SPCA536: */ 722/* case BRIDGE_SPCA536: */
710 gspca_dev->usb_buf[0] = Size; 723 gspca_dev->usb_buf[0] = Size;
711 reg_w(dev, 0x25, 0, 4, gspca_dev->usb_buf, 1); 724 reg_w(gspca_dev, 0x25, 0, 4, 1);
712 reg_r(dev, 0x25, 4, gspca_dev->usb_buf, 1); /* size */ 725 reg_r(gspca_dev, 0x25, 4, 1); /* size */
713 Type = 6; 726 Type = 6;
714 gspca_dev->usb_buf[0] = Type; 727 gspca_dev->usb_buf[0] = Type;
715 reg_w(dev, 0x27, 0, 0, gspca_dev->usb_buf, 1); 728 reg_w(gspca_dev, 0x27, 0, 0, 1);
716 reg_r(dev, 0x27, 0, gspca_dev->usb_buf, 1); /* type */ 729 reg_r(gspca_dev, 0x27, 0, 1); /* type */
717 rc = spca504B_PollingDataReady(gspca_dev); 730 rc = spca504B_PollingDataReady(gspca_dev);
718 break; 731 break;
719 case BRIDGE_SPCA504: 732 case BRIDGE_SPCA504:
@@ -752,18 +765,15 @@ static void spca504_wait_status(struct gspca_dev *gspca_dev)
752 765
753static void spca504B_setQtable(struct gspca_dev *gspca_dev) 766static void spca504B_setQtable(struct gspca_dev *gspca_dev)
754{ 767{
755 struct usb_device *dev = gspca_dev->dev;
756
757 gspca_dev->usb_buf[0] = 3; 768 gspca_dev->usb_buf[0] = 3;
758 reg_w(dev, 0x26, 0, 0, gspca_dev->usb_buf, 1); 769 reg_w(gspca_dev, 0x26, 0, 0, 1);
759 reg_r(dev, 0x26, 0, gspca_dev->usb_buf, 1); 770 reg_r(gspca_dev, 0x26, 0, 1);
760 spca504B_PollingDataReady(gspca_dev); 771 spca504B_PollingDataReady(gspca_dev);
761} 772}
762 773
763static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev) 774static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
764{ 775{
765 struct sd *sd = (struct sd *) gspca_dev; 776 struct sd *sd = (struct sd *) gspca_dev;
766 struct usb_device *dev = gspca_dev->dev;
767 int pollreg = 1; 777 int pollreg = 1;
768 778
769 switch (sd->bridge) { 779 switch (sd->bridge) {
@@ -774,20 +784,20 @@ static void sp5xx_initContBrigHueRegisters(struct gspca_dev *gspca_dev)
774 default: 784 default:
775/* case BRIDGE_SPCA533: */ 785/* case BRIDGE_SPCA533: */
776/* case BRIDGE_SPCA504B: */ 786/* case BRIDGE_SPCA504B: */
777 reg_w(dev, 0, 0, 0x21a7, NULL, 0); /* brightness */ 787 reg_w(gspca_dev, 0, 0, 0x21a7, 0); /* brightness */
778 reg_w(dev, 0, 0x20, 0x21a8, NULL, 0); /* contrast */ 788 reg_w(gspca_dev, 0, 0x20, 0x21a8, 0); /* contrast */
779 reg_w(dev, 0, 0, 0x21ad, NULL, 0); /* hue */ 789 reg_w(gspca_dev, 0, 0, 0x21ad, 0); /* hue */
780 reg_w(dev, 0, 1, 0x21ac, NULL, 0); /* sat/hue */ 790 reg_w(gspca_dev, 0, 1, 0x21ac, 0); /* sat/hue */
781 reg_w(dev, 0, 0x20, 0x21ae, NULL, 0); /* saturation */ 791 reg_w(gspca_dev, 0, 0x20, 0x21ae, 0); /* saturation */
782 reg_w(dev, 0, 0, 0x21a3, NULL, 0); /* gamma */ 792 reg_w(gspca_dev, 0, 0, 0x21a3, 0); /* gamma */
783 break; 793 break;
784 case BRIDGE_SPCA536: 794 case BRIDGE_SPCA536:
785 reg_w(dev, 0, 0, 0x20f0, NULL, 0); 795 reg_w(gspca_dev, 0, 0, 0x20f0, 0);
786 reg_w(dev, 0, 0x21, 0x20f1, NULL, 0); 796 reg_w(gspca_dev, 0, 0x21, 0x20f1, 0);
787 reg_w(dev, 0, 0x40, 0x20f5, NULL, 0); 797 reg_w(gspca_dev, 0, 0x40, 0x20f5, 0);
788 reg_w(dev, 0, 1, 0x20f4, NULL, 0); 798 reg_w(gspca_dev, 0, 1, 0x20f4, 0);
789 reg_w(dev, 0, 0x40, 0x20f6, NULL, 0); 799 reg_w(gspca_dev, 0, 0x40, 0x20f6, 0);
790 reg_w(dev, 0, 0, 0x2089, NULL, 0); 800 reg_w(gspca_dev, 0, 0, 0x2089, 0);
791 break; 801 break;
792 } 802 }
793 if (pollreg) 803 if (pollreg)
@@ -799,7 +809,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
799 const struct usb_device_id *id) 809 const struct usb_device_id *id)
800{ 810{
801 struct sd *sd = (struct sd *) gspca_dev; 811 struct sd *sd = (struct sd *) gspca_dev;
802 struct usb_device *dev = gspca_dev->dev;
803 struct cam *cam; 812 struct cam *cam;
804 813
805 cam = &gspca_dev->cam; 814 cam = &gspca_dev->cam;
@@ -811,7 +820,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
811 if (sd->subtype == AiptekMiniPenCam13) { 820 if (sd->subtype == AiptekMiniPenCam13) {
812/* try to get the firmware as some cam answer 2.0.1.2.2 821/* try to get the firmware as some cam answer 2.0.1.2.2
813 * and should be a spca504b then overwrite that setting */ 822 * and should be a spca504b then overwrite that setting */
814 reg_r(dev, 0x20, 0, gspca_dev->usb_buf, 1); 823 reg_r(gspca_dev, 0x20, 0, 1);
815 switch (gspca_dev->usb_buf[0]) { 824 switch (gspca_dev->usb_buf[0]) {
816 case 1: 825 case 1:
817 break; /* (right bridge/subtype) */ 826 break; /* (right bridge/subtype) */
@@ -848,8 +857,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
848 return 0; 857 return 0;
849} 858}
850 859
851/* this function is called at open time */ 860/* this function is called at probe and resume time */
852static int sd_open(struct gspca_dev *gspca_dev) 861static int sd_init(struct gspca_dev *gspca_dev)
853{ 862{
854 struct sd *sd = (struct sd *) gspca_dev; 863 struct sd *sd = (struct sd *) gspca_dev;
855 struct usb_device *dev = gspca_dev->dev; 864 struct usb_device *dev = gspca_dev->dev;
@@ -860,12 +869,12 @@ static int sd_open(struct gspca_dev *gspca_dev)
860 869
861 switch (sd->bridge) { 870 switch (sd->bridge) {
862 case BRIDGE_SPCA504B: 871 case BRIDGE_SPCA504B:
863 reg_w(dev, 0x1d, 0, 0, NULL, 0); 872 reg_w(gspca_dev, 0x1d, 0, 0, 0);
864 reg_w(dev, 0, 1, 0x2306, NULL, 0); 873 reg_w(gspca_dev, 0, 1, 0x2306, 0);
865 reg_w(dev, 0, 0, 0x0d04, NULL, 0); 874 reg_w(gspca_dev, 0, 0, 0x0d04, 0);
866 reg_w(dev, 0, 0, 0x2000, NULL, 0); 875 reg_w(gspca_dev, 0, 0, 0x2000, 0);
867 reg_w(dev, 0, 0x13, 0x2301, NULL, 0); 876 reg_w(gspca_dev, 0, 0x13, 0x2301, 0);
868 reg_w(dev, 0, 0, 0x2306, NULL, 0); 877 reg_w(gspca_dev, 0, 0, 0x2306, 0);
869 /* fall thru */ 878 /* fall thru */
870 case BRIDGE_SPCA533: 879 case BRIDGE_SPCA533:
871 rc = spca504B_PollingDataReady(gspca_dev); 880 rc = spca504B_PollingDataReady(gspca_dev);
@@ -873,12 +882,12 @@ static int sd_open(struct gspca_dev *gspca_dev)
873 break; 882 break;
874 case BRIDGE_SPCA536: 883 case BRIDGE_SPCA536:
875 spca50x_GetFirmware(gspca_dev); 884 spca50x_GetFirmware(gspca_dev);
876 reg_r(dev, 0x00, 0x5002, gspca_dev->usb_buf, 1); 885 reg_r(gspca_dev, 0x00, 0x5002, 1);
877 gspca_dev->usb_buf[0] = 0; 886 gspca_dev->usb_buf[0] = 0;
878 reg_w(dev, 0x24, 0, 0, gspca_dev->usb_buf, 1); 887 reg_w(gspca_dev, 0x24, 0, 0, 1);
879 reg_r(dev, 0x24, 0, gspca_dev->usb_buf, 1); 888 reg_r(gspca_dev, 0x24, 0, 1);
880 rc = spca504B_PollingDataReady(gspca_dev); 889 rc = spca504B_PollingDataReady(gspca_dev);
881 reg_w(dev, 0x34, 0, 0, NULL, 0); 890 reg_w(gspca_dev, 0x34, 0, 0, 0);
882 spca504B_WaitCmdStatus(gspca_dev); 891 spca504B_WaitCmdStatus(gspca_dev);
883 break; 892 break;
884 case BRIDGE_SPCA504C: /* pccam600 */ 893 case BRIDGE_SPCA504C: /* pccam600 */
@@ -971,12 +980,12 @@ static void sd_start(struct gspca_dev *gspca_dev)
971/* case BRIDGE_SPCA536: */ 980/* case BRIDGE_SPCA536: */
972 if (sd->subtype == MegapixV4 || 981 if (sd->subtype == MegapixV4 ||
973 sd->subtype == LogitechClickSmart820) { 982 sd->subtype == LogitechClickSmart820) {
974 reg_w(dev, 0xf0, 0, 0, NULL, 0); 983 reg_w(gspca_dev, 0xf0, 0, 0, 0);
975 spca504B_WaitCmdStatus(gspca_dev); 984 spca504B_WaitCmdStatus(gspca_dev);
976 reg_r(dev, 0xf0, 4, NULL, 0); 985 reg_r(gspca_dev, 0xf0, 4, 0);
977 spca504B_WaitCmdStatus(gspca_dev); 986 spca504B_WaitCmdStatus(gspca_dev);
978 } else { 987 } else {
979 reg_w(dev, 0x31, 0, 4, NULL, 0); 988 reg_w(gspca_dev, 0x31, 0, 4, 0);
980 spca504B_WaitCmdStatus(gspca_dev); 989 spca504B_WaitCmdStatus(gspca_dev);
981 rc = spca504B_PollingDataReady(gspca_dev); 990 rc = spca504B_PollingDataReady(gspca_dev);
982 } 991 }
@@ -1045,7 +1054,7 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1045/* case BRIDGE_SPCA533: */ 1054/* case BRIDGE_SPCA533: */
1046/* case BRIDGE_SPCA536: */ 1055/* case BRIDGE_SPCA536: */
1047/* case BRIDGE_SPCA504B: */ 1056/* case BRIDGE_SPCA504B: */
1048 reg_w(dev, 0x31, 0, 0, NULL, 0); 1057 reg_w(gspca_dev, 0x31, 0, 0, 0);
1049 spca504B_WaitCmdStatus(gspca_dev); 1058 spca504B_WaitCmdStatus(gspca_dev);
1050 spca504B_PollingDataReady(gspca_dev); 1059 spca504B_PollingDataReady(gspca_dev);
1051 break; 1060 break;
@@ -1069,14 +1078,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1069 } 1078 }
1070} 1079}
1071 1080
1072static void sd_stop0(struct gspca_dev *gspca_dev)
1073{
1074}
1075
1076static void sd_close(struct gspca_dev *gspca_dev)
1077{
1078}
1079
1080static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1081static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1081 struct gspca_frame *frame, /* target */ 1082 struct gspca_frame *frame, /* target */
1082 __u8 *data, /* isoc packet */ 1083 __u8 *data, /* isoc packet */
@@ -1369,11 +1370,9 @@ static const struct sd_desc sd_desc = {
1369 .ctrls = sd_ctrls, 1370 .ctrls = sd_ctrls,
1370 .nctrls = ARRAY_SIZE(sd_ctrls), 1371 .nctrls = ARRAY_SIZE(sd_ctrls),
1371 .config = sd_config, 1372 .config = sd_config,
1372 .open = sd_open, 1373 .init = sd_init,
1373 .start = sd_start, 1374 .start = sd_start,
1374 .stopN = sd_stopN, 1375 .stopN = sd_stopN,
1375 .stop0 = sd_stop0,
1376 .close = sd_close,
1377 .pkt_scan = sd_pkt_scan, 1376 .pkt_scan = sd_pkt_scan,
1378}; 1377};
1379 1378
@@ -1456,6 +1455,10 @@ static struct usb_driver sd_driver = {
1456 .id_table = device_table, 1455 .id_table = device_table,
1457 .probe = sd_probe, 1456 .probe = sd_probe,
1458 .disconnect = gspca_disconnect, 1457 .disconnect = gspca_disconnect,
1458#ifdef CONFIG_PM
1459 .suspend = gspca_suspend,
1460 .resume = gspca_resume,
1461#endif
1459}; 1462};
1460 1463
1461/* -- module insert / remove -- */ 1464/* -- module insert / remove -- */