diff options
Diffstat (limited to 'drivers/media/video/zr364xx.c')
-rw-r--r-- | drivers/media/video/zr364xx.c | 121 |
1 files changed, 67 insertions, 54 deletions
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c index a0e49dc66301..a1d81ed44c7c 100644 --- a/drivers/media/video/zr364xx.c +++ b/drivers/media/video/zr364xx.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/proc_fs.h> | 35 | #include <linux/proc_fs.h> |
36 | #include <linux/highmem.h> | 36 | #include <linux/highmem.h> |
37 | #include <media/v4l2-common.h> | 37 | #include <media/v4l2-common.h> |
38 | #include <media/v4l2-ioctl.h> | ||
38 | 39 | ||
39 | 40 | ||
40 | /* Version Information */ | 41 | /* Version Information */ |
@@ -51,7 +52,7 @@ | |||
51 | 52 | ||
52 | 53 | ||
53 | /* Debug macro */ | 54 | /* Debug macro */ |
54 | #define DBG(x...) if (debug) info(x) | 55 | #define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x) |
55 | 56 | ||
56 | 57 | ||
57 | /* Init methods, need to find nicer names for these | 58 | /* Init methods, need to find nicer names for these |
@@ -115,6 +116,7 @@ struct zr364xx_camera { | |||
115 | int height; | 116 | int height; |
116 | int method; | 117 | int method; |
117 | struct mutex lock; | 118 | struct mutex lock; |
119 | int users; | ||
118 | }; | 120 | }; |
119 | 121 | ||
120 | 122 | ||
@@ -126,7 +128,7 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value, | |||
126 | 128 | ||
127 | unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL); | 129 | unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL); |
128 | if (!transfer_buffer) { | 130 | if (!transfer_buffer) { |
129 | info("kmalloc(%d) failed", size); | 131 | dev_err(&udev->dev, "kmalloc(%d) failed\n", size); |
130 | return -ENOMEM; | 132 | return -ENOMEM; |
131 | } | 133 | } |
132 | 134 | ||
@@ -142,7 +144,8 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value, | |||
142 | kfree(transfer_buffer); | 144 | kfree(transfer_buffer); |
143 | 145 | ||
144 | if (status < 0) | 146 | if (status < 0) |
145 | info("Failed sending control message, error %d.", status); | 147 | dev_err(&udev->dev, |
148 | "Failed sending control message, error %d.\n", status); | ||
146 | 149 | ||
147 | return status; | 150 | return status; |
148 | } | 151 | } |
@@ -302,11 +305,11 @@ static int read_frame(struct zr364xx_camera *cam, int framenum) | |||
302 | DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]); | 305 | DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]); |
303 | DBG("bulk : n=%d size=%d", n, actual_length); | 306 | DBG("bulk : n=%d size=%d", n, actual_length); |
304 | if (n < 0) { | 307 | if (n < 0) { |
305 | info("error reading bulk msg"); | 308 | dev_err(&cam->udev->dev, "error reading bulk msg\n"); |
306 | return 0; | 309 | return 0; |
307 | } | 310 | } |
308 | if (actual_length < 0 || actual_length > BUFFER_SIZE) { | 311 | if (actual_length < 0 || actual_length > BUFFER_SIZE) { |
309 | info("wrong number of bytes"); | 312 | dev_err(&cam->udev->dev, "wrong number of bytes\n"); |
310 | return 0; | 313 | return 0; |
311 | } | 314 | } |
312 | 315 | ||
@@ -521,7 +524,7 @@ static int zr364xx_vidioc_g_ctrl(struct file *file, void *priv, | |||
521 | return 0; | 524 | return 0; |
522 | } | 525 | } |
523 | 526 | ||
524 | static int zr364xx_vidioc_enum_fmt_cap(struct file *file, | 527 | static int zr364xx_vidioc_enum_fmt_vid_cap(struct file *file, |
525 | void *priv, struct v4l2_fmtdesc *f) | 528 | void *priv, struct v4l2_fmtdesc *f) |
526 | { | 529 | { |
527 | if (f->index > 0) | 530 | if (f->index > 0) |
@@ -537,7 +540,7 @@ static int zr364xx_vidioc_enum_fmt_cap(struct file *file, | |||
537 | return 0; | 540 | return 0; |
538 | } | 541 | } |
539 | 542 | ||
540 | static int zr364xx_vidioc_try_fmt_cap(struct file *file, void *priv, | 543 | static int zr364xx_vidioc_try_fmt_vid_cap(struct file *file, void *priv, |
541 | struct v4l2_format *f) | 544 | struct v4l2_format *f) |
542 | { | 545 | { |
543 | struct video_device *vdev = video_devdata(file); | 546 | struct video_device *vdev = video_devdata(file); |
@@ -564,7 +567,7 @@ static int zr364xx_vidioc_try_fmt_cap(struct file *file, void *priv, | |||
564 | return 0; | 567 | return 0; |
565 | } | 568 | } |
566 | 569 | ||
567 | static int zr364xx_vidioc_g_fmt_cap(struct file *file, void *priv, | 570 | static int zr364xx_vidioc_g_fmt_vid_cap(struct file *file, void *priv, |
568 | struct v4l2_format *f) | 571 | struct v4l2_format *f) |
569 | { | 572 | { |
570 | struct video_device *vdev = video_devdata(file); | 573 | struct video_device *vdev = video_devdata(file); |
@@ -589,7 +592,7 @@ static int zr364xx_vidioc_g_fmt_cap(struct file *file, void *priv, | |||
589 | return 0; | 592 | return 0; |
590 | } | 593 | } |
591 | 594 | ||
592 | static int zr364xx_vidioc_s_fmt_cap(struct file *file, void *priv, | 595 | static int zr364xx_vidioc_s_fmt_vid_cap(struct file *file, void *priv, |
593 | struct v4l2_format *f) | 596 | struct v4l2_format *f) |
594 | { | 597 | { |
595 | struct video_device *vdev = video_devdata(file); | 598 | struct video_device *vdev = video_devdata(file); |
@@ -640,42 +643,47 @@ static int zr364xx_open(struct inode *inode, struct file *file) | |||
640 | 643 | ||
641 | DBG("zr364xx_open"); | 644 | DBG("zr364xx_open"); |
642 | 645 | ||
643 | cam->skip = 2; | 646 | mutex_lock(&cam->lock); |
644 | 647 | ||
645 | err = video_exclusive_open(inode, file); | 648 | if (cam->users) { |
646 | if (err < 0) | 649 | err = -EBUSY; |
647 | return err; | 650 | goto out; |
651 | } | ||
648 | 652 | ||
649 | if (!cam->framebuf) { | 653 | if (!cam->framebuf) { |
650 | cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES); | 654 | cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES); |
651 | if (!cam->framebuf) { | 655 | if (!cam->framebuf) { |
652 | info("vmalloc_32 failed!"); | 656 | dev_err(&cam->udev->dev, "vmalloc_32 failed!\n"); |
653 | return -ENOMEM; | 657 | err = -ENOMEM; |
658 | goto out; | ||
654 | } | 659 | } |
655 | } | 660 | } |
656 | 661 | ||
657 | mutex_lock(&cam->lock); | ||
658 | for (i = 0; init[cam->method][i].size != -1; i++) { | 662 | for (i = 0; init[cam->method][i].size != -1; i++) { |
659 | err = | 663 | err = |
660 | send_control_msg(udev, 1, init[cam->method][i].value, | 664 | send_control_msg(udev, 1, init[cam->method][i].value, |
661 | 0, init[cam->method][i].bytes, | 665 | 0, init[cam->method][i].bytes, |
662 | init[cam->method][i].size); | 666 | init[cam->method][i].size); |
663 | if (err < 0) { | 667 | if (err < 0) { |
664 | info("error during open sequence: %d", i); | 668 | dev_err(&cam->udev->dev, |
665 | mutex_unlock(&cam->lock); | 669 | "error during open sequence: %d\n", i); |
666 | return err; | 670 | goto out; |
667 | } | 671 | } |
668 | } | 672 | } |
669 | 673 | ||
674 | cam->skip = 2; | ||
675 | cam->users++; | ||
670 | file->private_data = vdev; | 676 | file->private_data = vdev; |
671 | 677 | ||
672 | /* Added some delay here, since opening/closing the camera quickly, | 678 | /* Added some delay here, since opening/closing the camera quickly, |
673 | * like Ekiga does during its startup, can crash the webcam | 679 | * like Ekiga does during its startup, can crash the webcam |
674 | */ | 680 | */ |
675 | mdelay(100); | 681 | mdelay(100); |
682 | err = 0; | ||
676 | 683 | ||
684 | out: | ||
677 | mutex_unlock(&cam->lock); | 685 | mutex_unlock(&cam->lock); |
678 | return 0; | 686 | return err; |
679 | } | 687 | } |
680 | 688 | ||
681 | 689 | ||
@@ -696,28 +704,30 @@ static int zr364xx_release(struct inode *inode, struct file *file) | |||
696 | udev = cam->udev; | 704 | udev = cam->udev; |
697 | 705 | ||
698 | mutex_lock(&cam->lock); | 706 | mutex_lock(&cam->lock); |
707 | |||
708 | cam->users--; | ||
709 | file->private_data = NULL; | ||
710 | |||
699 | for (i = 0; i < 2; i++) { | 711 | for (i = 0; i < 2; i++) { |
700 | err = | 712 | err = |
701 | send_control_msg(udev, 1, init[cam->method][i].value, | 713 | send_control_msg(udev, 1, init[cam->method][i].value, |
702 | 0, init[i][cam->method].bytes, | 714 | 0, init[i][cam->method].bytes, |
703 | init[cam->method][i].size); | 715 | init[cam->method][i].size); |
704 | if (err < 0) { | 716 | if (err < 0) { |
705 | info("error during release sequence"); | 717 | dev_err(&udev->dev, "error during release sequence\n"); |
706 | mutex_unlock(&cam->lock); | 718 | goto out; |
707 | return err; | ||
708 | } | 719 | } |
709 | } | 720 | } |
710 | 721 | ||
711 | file->private_data = NULL; | ||
712 | video_exclusive_release(inode, file); | ||
713 | |||
714 | /* Added some delay here, since opening/closing the camera quickly, | 722 | /* Added some delay here, since opening/closing the camera quickly, |
715 | * like Ekiga does during its startup, can crash the webcam | 723 | * like Ekiga does during its startup, can crash the webcam |
716 | */ | 724 | */ |
717 | mdelay(100); | 725 | mdelay(100); |
726 | err = 0; | ||
718 | 727 | ||
728 | out: | ||
719 | mutex_unlock(&cam->lock); | 729 | mutex_unlock(&cam->lock); |
720 | return 0; | 730 | return err; |
721 | } | 731 | } |
722 | 732 | ||
723 | 733 | ||
@@ -761,19 +771,12 @@ static const struct file_operations zr364xx_fops = { | |||
761 | .llseek = no_llseek, | 771 | .llseek = no_llseek, |
762 | }; | 772 | }; |
763 | 773 | ||
764 | static struct video_device zr364xx_template = { | 774 | static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = { |
765 | .owner = THIS_MODULE, | ||
766 | .name = DRIVER_DESC, | ||
767 | .type = VID_TYPE_CAPTURE, | ||
768 | .fops = &zr364xx_fops, | ||
769 | .release = video_device_release, | ||
770 | .minor = -1, | ||
771 | |||
772 | .vidioc_querycap = zr364xx_vidioc_querycap, | 775 | .vidioc_querycap = zr364xx_vidioc_querycap, |
773 | .vidioc_enum_fmt_cap = zr364xx_vidioc_enum_fmt_cap, | 776 | .vidioc_enum_fmt_vid_cap = zr364xx_vidioc_enum_fmt_vid_cap, |
774 | .vidioc_try_fmt_cap = zr364xx_vidioc_try_fmt_cap, | 777 | .vidioc_try_fmt_vid_cap = zr364xx_vidioc_try_fmt_vid_cap, |
775 | .vidioc_s_fmt_cap = zr364xx_vidioc_s_fmt_cap, | 778 | .vidioc_s_fmt_vid_cap = zr364xx_vidioc_s_fmt_vid_cap, |
776 | .vidioc_g_fmt_cap = zr364xx_vidioc_g_fmt_cap, | 779 | .vidioc_g_fmt_vid_cap = zr364xx_vidioc_g_fmt_vid_cap, |
777 | .vidioc_enum_input = zr364xx_vidioc_enum_input, | 780 | .vidioc_enum_input = zr364xx_vidioc_enum_input, |
778 | .vidioc_g_input = zr364xx_vidioc_g_input, | 781 | .vidioc_g_input = zr364xx_vidioc_g_input, |
779 | .vidioc_s_input = zr364xx_vidioc_s_input, | 782 | .vidioc_s_input = zr364xx_vidioc_s_input, |
@@ -784,6 +787,14 @@ static struct video_device zr364xx_template = { | |||
784 | .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl, | 787 | .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl, |
785 | }; | 788 | }; |
786 | 789 | ||
790 | static struct video_device zr364xx_template = { | ||
791 | .name = DRIVER_DESC, | ||
792 | .fops = &zr364xx_fops, | ||
793 | .ioctl_ops = &zr364xx_ioctl_ops, | ||
794 | .release = video_device_release, | ||
795 | .minor = -1, | ||
796 | }; | ||
797 | |||
787 | 798 | ||
788 | 799 | ||
789 | /*******************/ | 800 | /*******************/ |
@@ -799,13 +810,14 @@ static int zr364xx_probe(struct usb_interface *intf, | |||
799 | 810 | ||
800 | DBG("probing..."); | 811 | DBG("probing..."); |
801 | 812 | ||
802 | info(DRIVER_DESC " compatible webcam plugged"); | 813 | dev_info(&intf->dev, DRIVER_DESC " compatible webcam plugged\n"); |
803 | info("model %04x:%04x detected", udev->descriptor.idVendor, | 814 | dev_info(&intf->dev, "model %04x:%04x detected\n", |
804 | udev->descriptor.idProduct); | 815 | le16_to_cpu(udev->descriptor.idVendor), |
816 | le16_to_cpu(udev->descriptor.idProduct)); | ||
805 | 817 | ||
806 | cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL); | 818 | cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL); |
807 | if (cam == NULL) { | 819 | if (cam == NULL) { |
808 | info("cam: out of memory !"); | 820 | dev_err(&udev->dev, "cam: out of memory !\n"); |
809 | return -ENOMEM; | 821 | return -ENOMEM; |
810 | } | 822 | } |
811 | /* save the init method used by this camera */ | 823 | /* save the init method used by this camera */ |
@@ -813,7 +825,7 @@ static int zr364xx_probe(struct usb_interface *intf, | |||
813 | 825 | ||
814 | cam->vdev = video_device_alloc(); | 826 | cam->vdev = video_device_alloc(); |
815 | if (cam->vdev == NULL) { | 827 | if (cam->vdev == NULL) { |
816 | info("cam->vdev: out of memory !"); | 828 | dev_err(&udev->dev, "cam->vdev: out of memory !\n"); |
817 | kfree(cam); | 829 | kfree(cam); |
818 | return -ENOMEM; | 830 | return -ENOMEM; |
819 | } | 831 | } |
@@ -825,7 +837,7 @@ static int zr364xx_probe(struct usb_interface *intf, | |||
825 | cam->udev = udev; | 837 | cam->udev = udev; |
826 | 838 | ||
827 | if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) { | 839 | if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) { |
828 | info("cam->buffer: out of memory !"); | 840 | dev_info(&udev->dev, "cam->buffer: out of memory !\n"); |
829 | video_device_release(cam->vdev); | 841 | video_device_release(cam->vdev); |
830 | kfree(cam); | 842 | kfree(cam); |
831 | return -ENODEV; | 843 | return -ENODEV; |
@@ -833,17 +845,17 @@ static int zr364xx_probe(struct usb_interface *intf, | |||
833 | 845 | ||
834 | switch (mode) { | 846 | switch (mode) { |
835 | case 1: | 847 | case 1: |
836 | info("160x120 mode selected"); | 848 | dev_info(&udev->dev, "160x120 mode selected\n"); |
837 | cam->width = 160; | 849 | cam->width = 160; |
838 | cam->height = 120; | 850 | cam->height = 120; |
839 | break; | 851 | break; |
840 | case 2: | 852 | case 2: |
841 | info("640x480 mode selected"); | 853 | dev_info(&udev->dev, "640x480 mode selected\n"); |
842 | cam->width = 640; | 854 | cam->width = 640; |
843 | cam->height = 480; | 855 | cam->height = 480; |
844 | break; | 856 | break; |
845 | default: | 857 | default: |
846 | info("320x240 mode selected"); | 858 | dev_info(&udev->dev, "320x240 mode selected\n"); |
847 | cam->width = 320; | 859 | cam->width = 320; |
848 | cam->height = 240; | 860 | cam->height = 240; |
849 | break; | 861 | break; |
@@ -863,7 +875,7 @@ static int zr364xx_probe(struct usb_interface *intf, | |||
863 | 875 | ||
864 | err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1); | 876 | err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1); |
865 | if (err) { | 877 | if (err) { |
866 | info("video_register_device failed"); | 878 | dev_err(&udev->dev, "video_register_device failed\n"); |
867 | video_device_release(cam->vdev); | 879 | video_device_release(cam->vdev); |
868 | kfree(cam->buffer); | 880 | kfree(cam->buffer); |
869 | kfree(cam); | 881 | kfree(cam); |
@@ -872,7 +884,8 @@ static int zr364xx_probe(struct usb_interface *intf, | |||
872 | 884 | ||
873 | usb_set_intfdata(intf, cam); | 885 | usb_set_intfdata(intf, cam); |
874 | 886 | ||
875 | 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->num); | ||
876 | return 0; | 889 | return 0; |
877 | } | 890 | } |
878 | 891 | ||
@@ -882,7 +895,7 @@ static void zr364xx_disconnect(struct usb_interface *intf) | |||
882 | struct zr364xx_camera *cam = usb_get_intfdata(intf); | 895 | struct zr364xx_camera *cam = usb_get_intfdata(intf); |
883 | usb_set_intfdata(intf, NULL); | 896 | usb_set_intfdata(intf, NULL); |
884 | dev_set_drvdata(&intf->dev, NULL); | 897 | dev_set_drvdata(&intf->dev, NULL); |
885 | info(DRIVER_DESC " webcam unplugged"); | 898 | dev_info(&intf->dev, DRIVER_DESC " webcam unplugged\n"); |
886 | if (cam->vdev) | 899 | if (cam->vdev) |
887 | video_unregister_device(cam->vdev); | 900 | video_unregister_device(cam->vdev); |
888 | cam->vdev = NULL; | 901 | cam->vdev = NULL; |
@@ -911,16 +924,16 @@ static int __init zr364xx_init(void) | |||
911 | int retval; | 924 | int retval; |
912 | retval = usb_register(&zr364xx_driver); | 925 | retval = usb_register(&zr364xx_driver); |
913 | if (retval) | 926 | if (retval) |
914 | info("usb_register failed!"); | 927 | printk(KERN_ERR KBUILD_MODNAME ": usb_register failed!\n"); |
915 | else | 928 | else |
916 | info(DRIVER_DESC " module loaded"); | 929 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n"); |
917 | return retval; | 930 | return retval; |
918 | } | 931 | } |
919 | 932 | ||
920 | 933 | ||
921 | static void __exit zr364xx_exit(void) | 934 | static void __exit zr364xx_exit(void) |
922 | { | 935 | { |
923 | info(DRIVER_DESC " module unloaded"); | 936 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC " module unloaded\n"); |
924 | usb_deregister(&zr364xx_driver); | 937 | usb_deregister(&zr364xx_driver); |
925 | } | 938 | } |
926 | 939 | ||