aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/zr364xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/zr364xx.c')
-rw-r--r--drivers/media/video/zr364xx.c87
1 files changed, 49 insertions, 38 deletions
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 18d1c4ba79fb..7cdac99deea6 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -52,7 +52,7 @@
52 52
53 53
54/* Debug macro */ 54/* Debug macro */
55#define DBG(x...) if (debug) info(x) 55#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
56 56
57 57
58/* Init methods, need to find nicer names for these 58/* Init methods, need to find nicer names for these
@@ -116,6 +116,7 @@ struct zr364xx_camera {
116 int height; 116 int height;
117 int method; 117 int method;
118 struct mutex lock; 118 struct mutex lock;
119 int users;
119}; 120};
120 121
121 122
@@ -127,7 +128,7 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
127 128
128 unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL); 129 unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL);
129 if (!transfer_buffer) { 130 if (!transfer_buffer) {
130 info("kmalloc(%d) failed", size); 131 dev_err(&udev->dev, "kmalloc(%d) failed\n", size);
131 return -ENOMEM; 132 return -ENOMEM;
132 } 133 }
133 134
@@ -143,7 +144,8 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
143 kfree(transfer_buffer); 144 kfree(transfer_buffer);
144 145
145 if (status < 0) 146 if (status < 0)
146 info("Failed sending control message, error %d.", status); 147 dev_err(&udev->dev,
148 "Failed sending control message, error %d.\n", status);
147 149
148 return status; 150 return status;
149} 151}
@@ -303,11 +305,11 @@ static int read_frame(struct zr364xx_camera *cam, int framenum)
303 DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]); 305 DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]);
304 DBG("bulk : n=%d size=%d", n, actual_length); 306 DBG("bulk : n=%d size=%d", n, actual_length);
305 if (n < 0) { 307 if (n < 0) {
306 info("error reading bulk msg"); 308 dev_err(&cam->udev->dev, "error reading bulk msg\n");
307 return 0; 309 return 0;
308 } 310 }
309 if (actual_length < 0 || actual_length > BUFFER_SIZE) { 311 if (actual_length < 0 || actual_length > BUFFER_SIZE) {
310 info("wrong number of bytes"); 312 dev_err(&cam->udev->dev, "wrong number of bytes\n");
311 return 0; 313 return 0;
312 } 314 }
313 315
@@ -641,42 +643,47 @@ static int zr364xx_open(struct inode *inode, struct file *file)
641 643
642 DBG("zr364xx_open"); 644 DBG("zr364xx_open");
643 645
644 cam->skip = 2; 646 mutex_lock(&cam->lock);
645 647
646 err = video_exclusive_open(inode, file); 648 if (cam->users) {
647 if (err < 0) 649 err = -EBUSY;
648 return err; 650 goto out;
651 }
649 652
650 if (!cam->framebuf) { 653 if (!cam->framebuf) {
651 cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES); 654 cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES);
652 if (!cam->framebuf) { 655 if (!cam->framebuf) {
653 info("vmalloc_32 failed!"); 656 dev_err(&cam->udev->dev, "vmalloc_32 failed!\n");
654 return -ENOMEM; 657 err = -ENOMEM;
658 goto out;
655 } 659 }
656 } 660 }
657 661
658 mutex_lock(&cam->lock);
659 for (i = 0; init[cam->method][i].size != -1; i++) { 662 for (i = 0; init[cam->method][i].size != -1; i++) {
660 err = 663 err =
661 send_control_msg(udev, 1, init[cam->method][i].value, 664 send_control_msg(udev, 1, init[cam->method][i].value,
662 0, init[cam->method][i].bytes, 665 0, init[cam->method][i].bytes,
663 init[cam->method][i].size); 666 init[cam->method][i].size);
664 if (err < 0) { 667 if (err < 0) {
665 info("error during open sequence: %d", i); 668 dev_err(&cam->udev->dev,
666 mutex_unlock(&cam->lock); 669 "error during open sequence: %d\n", i);
667 return err; 670 goto out;
668 } 671 }
669 } 672 }
670 673
674 cam->skip = 2;
675 cam->users++;
671 file->private_data = vdev; 676 file->private_data = vdev;
672 677
673 /* Added some delay here, since opening/closing the camera quickly, 678 /* Added some delay here, since opening/closing the camera quickly,
674 * like Ekiga does during its startup, can crash the webcam 679 * like Ekiga does during its startup, can crash the webcam
675 */ 680 */
676 mdelay(100); 681 mdelay(100);
682 err = 0;
677 683
684out:
678 mutex_unlock(&cam->lock); 685 mutex_unlock(&cam->lock);
679 return 0; 686 return err;
680} 687}
681 688
682 689
@@ -697,28 +704,30 @@ static int zr364xx_release(struct inode *inode, struct file *file)
697 udev = cam->udev; 704 udev = cam->udev;
698 705
699 mutex_lock(&cam->lock); 706 mutex_lock(&cam->lock);
707
708 cam->users--;
709 file->private_data = NULL;
710
700 for (i = 0; i < 2; i++) { 711 for (i = 0; i < 2; i++) {
701 err = 712 err =
702 send_control_msg(udev, 1, init[cam->method][i].value, 713 send_control_msg(udev, 1, init[cam->method][i].value,
703 0, init[i][cam->method].bytes, 714 0, init[i][cam->method].bytes,
704 init[cam->method][i].size); 715 init[cam->method][i].size);
705 if (err < 0) { 716 if (err < 0) {
706 info("error during release sequence"); 717 dev_err(&udev->dev, "error during release sequence\n");
707 mutex_unlock(&cam->lock); 718 goto out;
708 return err;
709 } 719 }
710 } 720 }
711 721
712 file->private_data = NULL;
713 video_exclusive_release(inode, file);
714
715 /* Added some delay here, since opening/closing the camera quickly, 722 /* Added some delay here, since opening/closing the camera quickly,
716 * like Ekiga does during its startup, can crash the webcam 723 * like Ekiga does during its startup, can crash the webcam
717 */ 724 */
718 mdelay(100); 725 mdelay(100);
726 err = 0;
719 727
728out:
720 mutex_unlock(&cam->lock); 729 mutex_unlock(&cam->lock);
721 return 0; 730 return err;
722} 731}
723 732
724 733
@@ -801,13 +810,14 @@ static int zr364xx_probe(struct usb_interface *intf,
801 810
802 DBG("probing..."); 811 DBG("probing...");
803 812
804 info(DRIVER_DESC " compatible webcam plugged"); 813 dev_info(&intf->dev, DRIVER_DESC " compatible webcam plugged\n");
805 info("model %04x:%04x detected", udev->descriptor.idVendor, 814 dev_info(&intf->dev, "model %04x:%04x detected\n",
806 udev->descriptor.idProduct); 815 le16_to_cpu(udev->descriptor.idVendor),
816 le16_to_cpu(udev->descriptor.idProduct));
807 817
808 cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL); 818 cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL);
809 if (cam == NULL) { 819 if (cam == NULL) {
810 info("cam: out of memory !"); 820 dev_err(&udev->dev, "cam: out of memory !\n");
811 return -ENOMEM; 821 return -ENOMEM;
812 } 822 }
813 /* save the init method used by this camera */ 823 /* save the init method used by this camera */
@@ -815,7 +825,7 @@ static int zr364xx_probe(struct usb_interface *intf,
815 825
816 cam->vdev = video_device_alloc(); 826 cam->vdev = video_device_alloc();
817 if (cam->vdev == NULL) { 827 if (cam->vdev == NULL) {
818 info("cam->vdev: out of memory !"); 828 dev_err(&udev->dev, "cam->vdev: out of memory !\n");
819 kfree(cam); 829 kfree(cam);
820 return -ENOMEM; 830 return -ENOMEM;
821 } 831 }
@@ -827,7 +837,7 @@ static int zr364xx_probe(struct usb_interface *intf,
827 cam->udev = udev; 837 cam->udev = udev;
828 838
829 if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) { 839 if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) {
830 info("cam->buffer: out of memory !"); 840 dev_info(&udev->dev, "cam->buffer: out of memory !\n");
831 video_device_release(cam->vdev); 841 video_device_release(cam->vdev);
832 kfree(cam); 842 kfree(cam);
833 return -ENODEV; 843 return -ENODEV;
@@ -835,17 +845,17 @@ static int zr364xx_probe(struct usb_interface *intf,
835 845
836 switch (mode) { 846 switch (mode) {
837 case 1: 847 case 1:
838 info("160x120 mode selected"); 848 dev_info(&udev->dev, "160x120 mode selected\n");
839 cam->width = 160; 849 cam->width = 160;
840 cam->height = 120; 850 cam->height = 120;
841 break; 851 break;
842 case 2: 852 case 2:
843 info("640x480 mode selected"); 853 dev_info(&udev->dev, "640x480 mode selected\n");
844 cam->width = 640; 854 cam->width = 640;
845 cam->height = 480; 855 cam->height = 480;
846 break; 856 break;
847 default: 857 default:
848 info("320x240 mode selected"); 858 dev_info(&udev->dev, "320x240 mode selected\n");
849 cam->width = 320; 859 cam->width = 320;
850 cam->height = 240; 860 cam->height = 240;
851 break; 861 break;
@@ -865,7 +875,7 @@ static int zr364xx_probe(struct usb_interface *intf,
865 875
866 err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1); 876 err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1);
867 if (err) { 877 if (err) {
868 info("video_register_device failed"); 878 dev_err(&udev->dev, "video_register_device failed\n");
869 video_device_release(cam->vdev); 879 video_device_release(cam->vdev);
870 kfree(cam->buffer); 880 kfree(cam->buffer);
871 kfree(cam); 881 kfree(cam);
@@ -874,7 +884,8 @@ static int zr364xx_probe(struct usb_interface *intf,
874 884
875 usb_set_intfdata(intf, cam); 885 usb_set_intfdata(intf, cam);
876 886
877 info(DRIVER_DESC " controlling video device %d", cam->vdev->minor); 887 dev_info(&udev->dev, DRIVER_DESC " controlling video device %d\n",
888 cam->vdev->minor);
878 return 0; 889 return 0;
879} 890}
880 891
@@ -884,7 +895,7 @@ static void zr364xx_disconnect(struct usb_interface *intf)
884 struct zr364xx_camera *cam = usb_get_intfdata(intf); 895 struct zr364xx_camera *cam = usb_get_intfdata(intf);
885 usb_set_intfdata(intf, NULL); 896 usb_set_intfdata(intf, NULL);
886 dev_set_drvdata(&intf->dev, NULL); 897 dev_set_drvdata(&intf->dev, NULL);
887 info(DRIVER_DESC " webcam unplugged"); 898 dev_info(&intf->dev, DRIVER_DESC " webcam unplugged\n");
888 if (cam->vdev) 899 if (cam->vdev)
889 video_unregister_device(cam->vdev); 900 video_unregister_device(cam->vdev);
890 cam->vdev = NULL; 901 cam->vdev = NULL;
@@ -913,16 +924,16 @@ static int __init zr364xx_init(void)
913 int retval; 924 int retval;
914 retval = usb_register(&zr364xx_driver); 925 retval = usb_register(&zr364xx_driver);
915 if (retval) 926 if (retval)
916 info("usb_register failed!"); 927 printk(KERN_ERR KBUILD_MODNAME ": usb_register failed!\n");
917 else 928 else
918 info(DRIVER_DESC " module loaded"); 929 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
919 return retval; 930 return retval;
920} 931}
921 932
922 933
923static void __exit zr364xx_exit(void) 934static void __exit zr364xx_exit(void)
924{ 935{
925 info(DRIVER_DESC " module unloaded"); 936 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC " module unloaded\n");
926 usb_deregister(&zr364xx_driver); 937 usb_deregister(&zr364xx_driver);
927} 938}
928 939