linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / usb / image / mdc800.c
index 08daf40..0498711 100644 (file)
@@ -96,7 +96,6 @@
 #include <linux/module.h>
 #include <linux/smp_lock.h>
 #include <linux/wait.h>
-#include <linux/mutex.h>
 
 #include <linux/usb.h>
 #include <linux/fs.h>
@@ -170,7 +169,7 @@ struct mdc800_data
        int                     out_count;      // Bytes in the buffer
 
        int                     open;           // Camera device open ?
-       struct mutex            io_lock;        // IO -lock
+       struct semaphore        io_lock;        // IO -lock
 
        char                    in [8];         // Command Input Buffer
        int                     in_count;
@@ -498,7 +497,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
 
        info ("Found Mustek MDC800 on USB.");
 
-       mutex_lock(&mdc800->io_lock);
+       down (&mdc800->io_lock);
 
        retval = usb_register_dev(intf, &mdc800_class);
        if (retval) {
@@ -543,7 +542,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
 
        mdc800->state=READY;
 
-       mutex_unlock(&mdc800->io_lock);
+       up (&mdc800->io_lock);
        
        usb_set_intfdata(intf, mdc800);
        return 0;
@@ -621,7 +620,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
        int retval=0;
        int errn=0;
 
-       mutex_lock(&mdc800->io_lock);
+       down (&mdc800->io_lock);
        
        if (mdc800->state == NOT_CONNECTED)
        {
@@ -657,7 +656,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
        dbg ("Mustek MDC800 device opened.");
 
 error_out:
-       mutex_unlock(&mdc800->io_lock);
+       up (&mdc800->io_lock);
        return errn;
 }
 
@@ -670,7 +669,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
        int retval=0;
        dbg ("Mustek MDC800 device closed.");
 
-       mutex_lock(&mdc800->io_lock);
+       down (&mdc800->io_lock);
        if (mdc800->open && (mdc800->state != NOT_CONNECTED))
        {
                usb_kill_urb(mdc800->irq_urb);
@@ -683,7 +682,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
                retval=-EIO;
        }
 
-       mutex_unlock(&mdc800->io_lock);
+       up(&mdc800->io_lock);
        return retval;
 }
 
@@ -696,21 +695,21 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
        size_t left=len, sts=len; /* single transfer size */
        char __user *ptr = buf;
 
-       mutex_lock(&mdc800->io_lock);
+       down (&mdc800->io_lock);
        if (mdc800->state == NOT_CONNECTED)
        {
-               mutex_unlock(&mdc800->io_lock);
+               up (&mdc800->io_lock);
                return -EBUSY;
        }
        if (mdc800->state == WORKING)
        {
                warn ("Illegal State \"working\" reached during read ?!");
-               mutex_unlock(&mdc800->io_lock);
+               up (&mdc800->io_lock);
                return -EBUSY;
        }
        if (!mdc800->open)
        {
-               mutex_unlock(&mdc800->io_lock);
+               up (&mdc800->io_lock);
                return -EBUSY;
        }
 
@@ -718,7 +717,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
        {
                if (signal_pending (current)) 
                {
-                       mutex_unlock(&mdc800->io_lock);
+                       up (&mdc800->io_lock);
                        return -EINTR;
                }
 
@@ -737,7 +736,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
                                if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL))
                                {
                                        err ("Can't submit download urb (status=%i)",mdc800->download_urb->status);
-                                       mutex_unlock(&mdc800->io_lock);
+                                       up (&mdc800->io_lock);
                                        return len-left;
                                }
                                wait_event_timeout(mdc800->download_wait, mdc800->downloaded,
@@ -746,14 +745,14 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
                                if (mdc800->download_urb->status != 0)
                                {
                                        err ("request download-bytes fails (status=%i)",mdc800->download_urb->status);
-                                       mutex_unlock(&mdc800->io_lock);
+                                       up (&mdc800->io_lock);
                                        return len-left;
                                }
                        }
                        else
                        {
                                /* No more bytes -> that's an error*/
-                               mutex_unlock(&mdc800->io_lock);
+                               up (&mdc800->io_lock);
                                return -EIO;
                        }
                }
@@ -762,7 +761,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
                        /* Copy Bytes */
                        if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
                                                sts)) {
-                               mutex_unlock(&mdc800->io_lock);
+                               up(&mdc800->io_lock);
                                return -EFAULT;
                        }
                        ptr+=sts;
@@ -771,7 +770,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
                }
        }
 
-       mutex_unlock(&mdc800->io_lock);
+       up (&mdc800->io_lock);
        return len-left;
 }
 
@@ -786,15 +785,15 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
 {
        size_t i=0;
 
-       mutex_lock(&mdc800->io_lock);
+       down (&mdc800->io_lock);
        if (mdc800->state != READY)
        {
-               mutex_unlock(&mdc800->io_lock);
+               up (&mdc800->io_lock);
                return -EBUSY;
        }
        if (!mdc800->open )
        {
-               mutex_unlock(&mdc800->io_lock);
+               up (&mdc800->io_lock);
                return -EBUSY;
        }
 
@@ -803,13 +802,13 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                unsigned char c;
                if (signal_pending (current)) 
                {
-                       mutex_unlock(&mdc800->io_lock);
+                       up (&mdc800->io_lock);
                        return -EINTR;
                }
                
                if(get_user(c, buf+i))
                {
-                       mutex_unlock(&mdc800->io_lock);
+                       up(&mdc800->io_lock);
                        return -EFAULT;
                }
 
@@ -830,7 +829,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                }
                else
                {
-                       mutex_unlock(&mdc800->io_lock);
+                       up (&mdc800->io_lock);
                        return -EIO;
                }
 
@@ -842,7 +841,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                        if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
                        {
                                err ("Camera didn't get ready.\n");
-                               mutex_unlock(&mdc800->io_lock);
+                               up (&mdc800->io_lock);
                                return -EIO;
                        }
 
@@ -854,7 +853,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                        if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL))
                        {
                                err ("submitting write urb fails (status=%i)", mdc800->write_urb->status);
-                               mutex_unlock(&mdc800->io_lock);
+                               up (&mdc800->io_lock);
                                return -EIO;
                        }
                        wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000);
@@ -862,7 +861,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                        if (mdc800->state == WORKING)
                        {
                                usb_kill_urb(mdc800->write_urb);
-                               mutex_unlock(&mdc800->io_lock);
+                               up (&mdc800->io_lock);
                                return -EIO;
                        }
 
@@ -874,7 +873,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                                        {
                                                err ("call 0x07 before 0x05,0x3e");
                                                mdc800->state=READY;
-                                               mutex_unlock(&mdc800->io_lock);
+                                               up (&mdc800->io_lock);
                                                return -EIO;
                                        }
                                        mdc800->pic_len=-1;
@@ -893,7 +892,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                                                if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ))
                                                {
                                                        err ("requesting answer from irq fails");
-                                                       mutex_unlock(&mdc800->io_lock);
+                                                       up (&mdc800->io_lock);
                                                        return -EIO;
                                                }
 
@@ -921,7 +920,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                                                if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND))
                                                {
                                                        err ("Command Timeout.");
-                                                       mutex_unlock(&mdc800->io_lock);
+                                                       up (&mdc800->io_lock);
                                                        return -EIO;
                                                }
                                        }
@@ -931,7 +930,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
                }
                i++;
        }
-       mutex_unlock(&mdc800->io_lock);
+       up (&mdc800->io_lock);
        return i;
 }
 
@@ -979,13 +978,15 @@ static int __init usb_mdc800_init (void)
 {
        int retval = -ENODEV;
        /* Allocate Memory */
-       mdc800=kzalloc (sizeof (struct mdc800_data), GFP_KERNEL);
+       mdc800=kmalloc (sizeof (struct mdc800_data), GFP_KERNEL);
        if (!mdc800)
                goto cleanup_on_fail;
 
+       memset(mdc800, 0, sizeof(struct mdc800_data));
        mdc800->dev = NULL;
+       mdc800->open=0;
        mdc800->state=NOT_CONNECTED;
-       mutex_init (&mdc800->io_lock);
+       init_MUTEX (&mdc800->io_lock);
 
        init_waitqueue_head (&mdc800->irq_wait);
        init_waitqueue_head (&mdc800->write_wait);