diff options
Diffstat (limited to 'drivers/usb/image')
-rw-r--r-- | drivers/usb/image/mdc800.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c index 4e3e4d048c14..08daf400f985 100644 --- a/drivers/usb/image/mdc800.c +++ b/drivers/usb/image/mdc800.c | |||
@@ -96,6 +96,7 @@ | |||
96 | #include <linux/module.h> | 96 | #include <linux/module.h> |
97 | #include <linux/smp_lock.h> | 97 | #include <linux/smp_lock.h> |
98 | #include <linux/wait.h> | 98 | #include <linux/wait.h> |
99 | #include <linux/mutex.h> | ||
99 | 100 | ||
100 | #include <linux/usb.h> | 101 | #include <linux/usb.h> |
101 | #include <linux/fs.h> | 102 | #include <linux/fs.h> |
@@ -169,7 +170,7 @@ struct mdc800_data | |||
169 | int out_count; // Bytes in the buffer | 170 | int out_count; // Bytes in the buffer |
170 | 171 | ||
171 | int open; // Camera device open ? | 172 | int open; // Camera device open ? |
172 | struct semaphore io_lock; // IO -lock | 173 | struct mutex io_lock; // IO -lock |
173 | 174 | ||
174 | char in [8]; // Command Input Buffer | 175 | char in [8]; // Command Input Buffer |
175 | int in_count; | 176 | int in_count; |
@@ -497,7 +498,7 @@ static int mdc800_usb_probe (struct usb_interface *intf, | |||
497 | 498 | ||
498 | info ("Found Mustek MDC800 on USB."); | 499 | info ("Found Mustek MDC800 on USB."); |
499 | 500 | ||
500 | down (&mdc800->io_lock); | 501 | mutex_lock(&mdc800->io_lock); |
501 | 502 | ||
502 | retval = usb_register_dev(intf, &mdc800_class); | 503 | retval = usb_register_dev(intf, &mdc800_class); |
503 | if (retval) { | 504 | if (retval) { |
@@ -542,7 +543,7 @@ static int mdc800_usb_probe (struct usb_interface *intf, | |||
542 | 543 | ||
543 | mdc800->state=READY; | 544 | mdc800->state=READY; |
544 | 545 | ||
545 | up (&mdc800->io_lock); | 546 | mutex_unlock(&mdc800->io_lock); |
546 | 547 | ||
547 | usb_set_intfdata(intf, mdc800); | 548 | usb_set_intfdata(intf, mdc800); |
548 | return 0; | 549 | return 0; |
@@ -620,7 +621,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file) | |||
620 | int retval=0; | 621 | int retval=0; |
621 | int errn=0; | 622 | int errn=0; |
622 | 623 | ||
623 | down (&mdc800->io_lock); | 624 | mutex_lock(&mdc800->io_lock); |
624 | 625 | ||
625 | if (mdc800->state == NOT_CONNECTED) | 626 | if (mdc800->state == NOT_CONNECTED) |
626 | { | 627 | { |
@@ -656,7 +657,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file) | |||
656 | dbg ("Mustek MDC800 device opened."); | 657 | dbg ("Mustek MDC800 device opened."); |
657 | 658 | ||
658 | error_out: | 659 | error_out: |
659 | up (&mdc800->io_lock); | 660 | mutex_unlock(&mdc800->io_lock); |
660 | return errn; | 661 | return errn; |
661 | } | 662 | } |
662 | 663 | ||
@@ -669,7 +670,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file) | |||
669 | int retval=0; | 670 | int retval=0; |
670 | dbg ("Mustek MDC800 device closed."); | 671 | dbg ("Mustek MDC800 device closed."); |
671 | 672 | ||
672 | down (&mdc800->io_lock); | 673 | mutex_lock(&mdc800->io_lock); |
673 | if (mdc800->open && (mdc800->state != NOT_CONNECTED)) | 674 | if (mdc800->open && (mdc800->state != NOT_CONNECTED)) |
674 | { | 675 | { |
675 | usb_kill_urb(mdc800->irq_urb); | 676 | usb_kill_urb(mdc800->irq_urb); |
@@ -682,7 +683,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file) | |||
682 | retval=-EIO; | 683 | retval=-EIO; |
683 | } | 684 | } |
684 | 685 | ||
685 | up(&mdc800->io_lock); | 686 | mutex_unlock(&mdc800->io_lock); |
686 | return retval; | 687 | return retval; |
687 | } | 688 | } |
688 | 689 | ||
@@ -695,21 +696,21 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
695 | size_t left=len, sts=len; /* single transfer size */ | 696 | size_t left=len, sts=len; /* single transfer size */ |
696 | char __user *ptr = buf; | 697 | char __user *ptr = buf; |
697 | 698 | ||
698 | down (&mdc800->io_lock); | 699 | mutex_lock(&mdc800->io_lock); |
699 | if (mdc800->state == NOT_CONNECTED) | 700 | if (mdc800->state == NOT_CONNECTED) |
700 | { | 701 | { |
701 | up (&mdc800->io_lock); | 702 | mutex_unlock(&mdc800->io_lock); |
702 | return -EBUSY; | 703 | return -EBUSY; |
703 | } | 704 | } |
704 | if (mdc800->state == WORKING) | 705 | if (mdc800->state == WORKING) |
705 | { | 706 | { |
706 | warn ("Illegal State \"working\" reached during read ?!"); | 707 | warn ("Illegal State \"working\" reached during read ?!"); |
707 | up (&mdc800->io_lock); | 708 | mutex_unlock(&mdc800->io_lock); |
708 | return -EBUSY; | 709 | return -EBUSY; |
709 | } | 710 | } |
710 | if (!mdc800->open) | 711 | if (!mdc800->open) |
711 | { | 712 | { |
712 | up (&mdc800->io_lock); | 713 | mutex_unlock(&mdc800->io_lock); |
713 | return -EBUSY; | 714 | return -EBUSY; |
714 | } | 715 | } |
715 | 716 | ||
@@ -717,7 +718,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
717 | { | 718 | { |
718 | if (signal_pending (current)) | 719 | if (signal_pending (current)) |
719 | { | 720 | { |
720 | up (&mdc800->io_lock); | 721 | mutex_unlock(&mdc800->io_lock); |
721 | return -EINTR; | 722 | return -EINTR; |
722 | } | 723 | } |
723 | 724 | ||
@@ -736,7 +737,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
736 | if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL)) | 737 | if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL)) |
737 | { | 738 | { |
738 | err ("Can't submit download urb (status=%i)",mdc800->download_urb->status); | 739 | err ("Can't submit download urb (status=%i)",mdc800->download_urb->status); |
739 | up (&mdc800->io_lock); | 740 | mutex_unlock(&mdc800->io_lock); |
740 | return len-left; | 741 | return len-left; |
741 | } | 742 | } |
742 | wait_event_timeout(mdc800->download_wait, mdc800->downloaded, | 743 | wait_event_timeout(mdc800->download_wait, mdc800->downloaded, |
@@ -745,14 +746,14 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
745 | if (mdc800->download_urb->status != 0) | 746 | if (mdc800->download_urb->status != 0) |
746 | { | 747 | { |
747 | err ("request download-bytes fails (status=%i)",mdc800->download_urb->status); | 748 | err ("request download-bytes fails (status=%i)",mdc800->download_urb->status); |
748 | up (&mdc800->io_lock); | 749 | mutex_unlock(&mdc800->io_lock); |
749 | return len-left; | 750 | return len-left; |
750 | } | 751 | } |
751 | } | 752 | } |
752 | else | 753 | else |
753 | { | 754 | { |
754 | /* No more bytes -> that's an error*/ | 755 | /* No more bytes -> that's an error*/ |
755 | up (&mdc800->io_lock); | 756 | mutex_unlock(&mdc800->io_lock); |
756 | return -EIO; | 757 | return -EIO; |
757 | } | 758 | } |
758 | } | 759 | } |
@@ -761,7 +762,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
761 | /* Copy Bytes */ | 762 | /* Copy Bytes */ |
762 | if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr], | 763 | if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr], |
763 | sts)) { | 764 | sts)) { |
764 | up(&mdc800->io_lock); | 765 | mutex_unlock(&mdc800->io_lock); |
765 | return -EFAULT; | 766 | return -EFAULT; |
766 | } | 767 | } |
767 | ptr+=sts; | 768 | ptr+=sts; |
@@ -770,7 +771,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l | |||
770 | } | 771 | } |
771 | } | 772 | } |
772 | 773 | ||
773 | up (&mdc800->io_lock); | 774 | mutex_unlock(&mdc800->io_lock); |
774 | return len-left; | 775 | return len-left; |
775 | } | 776 | } |
776 | 777 | ||
@@ -785,15 +786,15 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
785 | { | 786 | { |
786 | size_t i=0; | 787 | size_t i=0; |
787 | 788 | ||
788 | down (&mdc800->io_lock); | 789 | mutex_lock(&mdc800->io_lock); |
789 | if (mdc800->state != READY) | 790 | if (mdc800->state != READY) |
790 | { | 791 | { |
791 | up (&mdc800->io_lock); | 792 | mutex_unlock(&mdc800->io_lock); |
792 | return -EBUSY; | 793 | return -EBUSY; |
793 | } | 794 | } |
794 | if (!mdc800->open ) | 795 | if (!mdc800->open ) |
795 | { | 796 | { |
796 | up (&mdc800->io_lock); | 797 | mutex_unlock(&mdc800->io_lock); |
797 | return -EBUSY; | 798 | return -EBUSY; |
798 | } | 799 | } |
799 | 800 | ||
@@ -802,13 +803,13 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
802 | unsigned char c; | 803 | unsigned char c; |
803 | if (signal_pending (current)) | 804 | if (signal_pending (current)) |
804 | { | 805 | { |
805 | up (&mdc800->io_lock); | 806 | mutex_unlock(&mdc800->io_lock); |
806 | return -EINTR; | 807 | return -EINTR; |
807 | } | 808 | } |
808 | 809 | ||
809 | if(get_user(c, buf+i)) | 810 | if(get_user(c, buf+i)) |
810 | { | 811 | { |
811 | up(&mdc800->io_lock); | 812 | mutex_unlock(&mdc800->io_lock); |
812 | return -EFAULT; | 813 | return -EFAULT; |
813 | } | 814 | } |
814 | 815 | ||
@@ -829,7 +830,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
829 | } | 830 | } |
830 | else | 831 | else |
831 | { | 832 | { |
832 | up (&mdc800->io_lock); | 833 | mutex_unlock(&mdc800->io_lock); |
833 | return -EIO; | 834 | return -EIO; |
834 | } | 835 | } |
835 | 836 | ||
@@ -841,7 +842,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
841 | if (mdc800_usb_waitForIRQ (0,TO_GET_READY)) | 842 | if (mdc800_usb_waitForIRQ (0,TO_GET_READY)) |
842 | { | 843 | { |
843 | err ("Camera didn't get ready.\n"); | 844 | err ("Camera didn't get ready.\n"); |
844 | up (&mdc800->io_lock); | 845 | mutex_unlock(&mdc800->io_lock); |
845 | return -EIO; | 846 | return -EIO; |
846 | } | 847 | } |
847 | 848 | ||
@@ -853,7 +854,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
853 | if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL)) | 854 | if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL)) |
854 | { | 855 | { |
855 | err ("submitting write urb fails (status=%i)", mdc800->write_urb->status); | 856 | err ("submitting write urb fails (status=%i)", mdc800->write_urb->status); |
856 | up (&mdc800->io_lock); | 857 | mutex_unlock(&mdc800->io_lock); |
857 | return -EIO; | 858 | return -EIO; |
858 | } | 859 | } |
859 | wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000); | 860 | wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000); |
@@ -861,7 +862,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
861 | if (mdc800->state == WORKING) | 862 | if (mdc800->state == WORKING) |
862 | { | 863 | { |
863 | usb_kill_urb(mdc800->write_urb); | 864 | usb_kill_urb(mdc800->write_urb); |
864 | up (&mdc800->io_lock); | 865 | mutex_unlock(&mdc800->io_lock); |
865 | return -EIO; | 866 | return -EIO; |
866 | } | 867 | } |
867 | 868 | ||
@@ -873,7 +874,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
873 | { | 874 | { |
874 | err ("call 0x07 before 0x05,0x3e"); | 875 | err ("call 0x07 before 0x05,0x3e"); |
875 | mdc800->state=READY; | 876 | mdc800->state=READY; |
876 | up (&mdc800->io_lock); | 877 | mutex_unlock(&mdc800->io_lock); |
877 | return -EIO; | 878 | return -EIO; |
878 | } | 879 | } |
879 | mdc800->pic_len=-1; | 880 | mdc800->pic_len=-1; |
@@ -892,7 +893,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
892 | if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ)) | 893 | if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ)) |
893 | { | 894 | { |
894 | err ("requesting answer from irq fails"); | 895 | err ("requesting answer from irq fails"); |
895 | up (&mdc800->io_lock); | 896 | mutex_unlock(&mdc800->io_lock); |
896 | return -EIO; | 897 | return -EIO; |
897 | } | 898 | } |
898 | 899 | ||
@@ -920,7 +921,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
920 | if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND)) | 921 | if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND)) |
921 | { | 922 | { |
922 | err ("Command Timeout."); | 923 | err ("Command Timeout."); |
923 | up (&mdc800->io_lock); | 924 | mutex_unlock(&mdc800->io_lock); |
924 | return -EIO; | 925 | return -EIO; |
925 | } | 926 | } |
926 | } | 927 | } |
@@ -930,7 +931,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s | |||
930 | } | 931 | } |
931 | i++; | 932 | i++; |
932 | } | 933 | } |
933 | up (&mdc800->io_lock); | 934 | mutex_unlock(&mdc800->io_lock); |
934 | return i; | 935 | return i; |
935 | } | 936 | } |
936 | 937 | ||
@@ -984,7 +985,7 @@ static int __init usb_mdc800_init (void) | |||
984 | 985 | ||
985 | mdc800->dev = NULL; | 986 | mdc800->dev = NULL; |
986 | mdc800->state=NOT_CONNECTED; | 987 | mdc800->state=NOT_CONNECTED; |
987 | init_MUTEX (&mdc800->io_lock); | 988 | mutex_init (&mdc800->io_lock); |
988 | 989 | ||
989 | init_waitqueue_head (&mdc800->irq_wait); | 990 | init_waitqueue_head (&mdc800->irq_wait); |
990 | init_waitqueue_head (&mdc800->write_wait); | 991 | init_waitqueue_head (&mdc800->write_wait); |