Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / drivers / usb / mdc800.c
blob131681c8e7815c03f7e8a27cdbf73f76109251ae
1 /*
2 * copyright (C) 1999/2000 by Henning Zabel <henning@uni-paderborn.de>
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * USB-Kernel Driver for the Mustek MDC800 Digital Camera
22 * (c) 1999/2000 Henning Zabel <henning@uni-paderborn.de>
25 * The driver brings the USB functions of the MDC800 to Linux.
26 * To use the Camera you must support the USB Protocoll of the camera
27 * to the Kernel Node.
28 * The Driver uses a misc device Node. Create it with :
29 * mknod /dev/mustek c 180 32
31 * The driver supports only one camera.
33 * version 0.7.5
34 * Fixed potential SMP races with Spinlocks.
35 * Thanks to Oliver Neukum <oliver.neukum@lrz.uni-muenchen.de> who
36 * noticed the race conditions.
37 * (30/10/2000)
39 * Fixed: Setting urb->dev before submitting urb.
40 * by Greg KH <greg@kroah.com>
41 * (13/10/2000)
43 * version 0.7.3
44 * bugfix : The mdc800->state field gets set to READY after the
45 * the diconnect function sets it to NOT_CONNECTED. This makes the
46 * driver running like the camera is connected and causes some
47 * hang ups.
49 * version 0.7.1
50 * MOD_INC and MOD_DEC are changed in usb_probe to prevent load/unload
51 * problems when compiled as Module.
52 * (04/04/2000)
54 * The mdc800 driver gets assigned the USB Minor 32-47. The Registration
55 * was updated to use these values.
56 * (26/03/2000)
58 * The Init und Exit Module Function are updated.
59 * (01/03/2000)
61 * version 0.7.0
62 * Rewrite of the driver : The driver now uses URB's. The old stuff
63 * has been removed.
65 * version 0.6.0
66 * Rewrite of this driver: The Emulation of the rs232 protocoll
67 * has been removed from the driver. A special executeCommand function
68 * for this driver is included to gphoto.
69 * The driver supports two kind of communication to bulk endpoints.
70 * Either with the dev->bus->ops->bulk... or with callback function.
71 * (09/11/1999)
73 * version 0.5.0:
74 * first Version that gets a version number. Most of the needed
75 * functions work.
76 * (20/10/1999)
79 #include <linux/version.h>
80 #include <linux/sched.h>
81 #include <linux/signal.h>
82 #include <linux/spinlock.h>
83 #include <linux/errno.h>
84 #include <linux/random.h>
85 #include <linux/poll.h>
86 #include <linux/init.h>
87 #include <linux/malloc.h>
88 #include <linux/module.h>
89 #include <linux/smp_lock.h>
91 #include <linux/usb.h>
93 #define VERSION "0.7.5"
94 #define RELEASE_DATE "(30/10/2000)"
96 /* Vendor and Product Information */
97 #define MDC800_VENDOR_ID 0x055f
98 #define MDC800_PRODUCT_ID 0xa800
100 /* Timeouts (msec) */
101 #define TO_DOWNLOAD_GET_READY 1500
102 #define TO_DOWNLOAD_GET_BUSY 1500
103 #define TO_WRITE_GET_READY 1000
104 #define TO_DEFAULT_COMMAND 5000
105 #define TO_READ_FROM_IRQ TO_DEFAULT_COMMAND
106 #define TO_GET_READY TO_DEFAULT_COMMAND
108 /* Minor Number of the device (create with mknod /dev/mustek c 180 32) */
109 #define MDC800_DEVICE_MINOR_BASE 32
112 /**************************************************************************
113 Data and structs
114 ***************************************************************************/
117 typedef enum {
118 NOT_CONNECTED, READY, WORKING, DOWNLOAD
119 } mdc800_state;
122 /* Data for the driver */
123 struct mdc800_data
125 struct usb_device * dev; // Device Data
126 mdc800_state state;
128 unsigned int endpoint [4];
130 purb_t irq_urb;
131 wait_queue_head_t irq_wait;
132 char* irq_urb_buffer;
134 int camera_busy; // is camera busy ?
135 int camera_request_ready; // Status to synchronize with irq
136 char camera_response [8]; // last Bytes send after busy
138 purb_t write_urb;
139 char* write_urb_buffer;
140 wait_queue_head_t write_wait;
143 purb_t download_urb;
144 char* download_urb_buffer;
145 wait_queue_head_t download_wait;
146 int download_left; // Bytes left to download ?
149 /* Device Data */
150 char out [64]; // Answer Buffer
151 int out_ptr; // Index to the first not readen byte
152 int out_count; // Bytes in the buffer
154 int open; // Camera device open ?
155 spinlock_t io_lock; // IO -lock
157 char in [8]; // Command Input Buffer
158 int in_count;
160 int pic_index; // Cache for the Imagesize (-1 for nothing cached )
161 int pic_len;
165 /* Specification of the Endpoints */
166 static struct usb_endpoint_descriptor mdc800_ed [4] =
168 { 0,0, 0x01, 0x02, 8, 0,0,0 },
169 { 0,0, 0x82, 0x03, 8, 0,0,0 },
170 { 0,0, 0x03, 0x02, 64, 0,0,0 },
171 { 0,0, 0x84, 0x02, 64, 0,0,0 }
175 /* The Variable used by the driver */
176 static struct mdc800_data* mdc800=0;
179 /***************************************************************************
180 The USB Part of the driver
181 ****************************************************************************/
183 static int mdc800_endpoint_equals (struct usb_endpoint_descriptor *a,struct usb_endpoint_descriptor *b)
185 return (
186 ( a->bEndpointAddress == b->bEndpointAddress )
187 && ( a->bmAttributes == b->bmAttributes )
188 && ( a->wMaxPacketSize == b->wMaxPacketSize )
194 * Checks wether the camera responds busy
196 static int mdc800_isBusy (char* ch)
198 int i=0;
199 while (i<8)
201 if (ch [i] != (char)0x99)
202 return 0;
203 i++;
205 return 1;
210 * Checks wether the Camera is ready
212 static int mdc800_isReady (char *ch)
214 int i=0;
215 while (i<8)
217 if (ch [i] != (char)0xbb)
218 return 0;
219 i++;
221 return 1;
227 * USB IRQ Handler for InputLine
229 static void mdc800_usb_irq (struct urb *urb)
231 int data_received=0, wake_up;
232 unsigned char* b=urb->transfer_buffer;
233 struct mdc800_data* mdc800=urb->context;
235 if (urb->status >= 0)
238 //dbg ("%i %i %i %i %i %i %i %i \n",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]);
240 if (mdc800_isBusy (b))
242 if (!mdc800->camera_busy)
244 mdc800->camera_busy=1;
245 dbg ("gets busy");
248 else
250 if (mdc800->camera_busy && mdc800_isReady (b))
252 mdc800->camera_busy=0;
253 dbg ("gets ready");
256 if (!(mdc800_isBusy (b) || mdc800_isReady (b)))
258 /* Store Data in camera_answer field */
259 dbg ("%i %i %i %i %i %i %i %i ",b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]);
261 memcpy (mdc800->camera_response,b,8);
262 data_received=1;
265 wake_up= ( mdc800->camera_request_ready > 0 )
268 ((mdc800->camera_request_ready == 1) && (!mdc800->camera_busy))
270 ((mdc800->camera_request_ready == 2) && data_received)
272 ((mdc800->camera_request_ready == 3) && (mdc800->camera_busy))
274 (urb->status < 0)
277 if (wake_up)
279 mdc800->camera_request_ready=0;
280 wake_up_interruptible (&mdc800->irq_wait);
286 * Waits a while until the irq responds that camera is ready
288 * mode : 0: Wait for camera gets ready
289 * 1: Wait for receiving data
290 * 2: Wait for camera gets busy
292 * msec: Time to wait
294 static int mdc800_usb_waitForIRQ (int mode, int msec)
296 mdc800->camera_request_ready=1+mode;
298 interruptible_sleep_on_timeout (&mdc800->irq_wait, msec*HZ/1000);
300 if (mdc800->camera_request_ready>0)
302 mdc800->camera_request_ready=0;
303 err ("timeout waiting for camera.");
304 return -1;
307 if (mdc800->state == NOT_CONNECTED)
309 warn ("Camera gets disconnected during waiting for irq.");
310 mdc800->camera_request_ready=0;
311 return -2;
314 return 0;
319 * The write_urb callback function
321 static void mdc800_usb_write_notify (struct urb *urb)
323 struct mdc800_data* mdc800=urb->context;
325 if (urb->status != 0)
327 err ("writing command fails (status=%i)", urb->status);
329 else
331 mdc800->state=READY;
333 wake_up_interruptible (&mdc800->write_wait);
338 * The download_urb callback function
340 static void mdc800_usb_download_notify (struct urb *urb)
342 struct mdc800_data* mdc800=urb->context;
344 if (urb->status == 0)
346 /* Fill output buffer with these data */
347 memcpy (mdc800->out, urb->transfer_buffer, 64);
348 mdc800->out_count=64;
349 mdc800->out_ptr=0;
350 mdc800->download_left-=64;
351 if (mdc800->download_left == 0)
353 mdc800->state=READY;
356 else
358 err ("request bytes fails (status:%i)", urb->status);
360 wake_up_interruptible (&mdc800->download_wait);
364 /***************************************************************************
365 Probing for the Camera
366 ***************************************************************************/
368 static struct usb_driver mdc800_usb_driver;
371 * Callback to search the Mustek MDC800 on the USB Bus
373 static void* mdc800_usb_probe (struct usb_device *dev ,unsigned int ifnum,
374 const struct usb_device_id *id)
376 int i,j;
377 struct usb_interface_descriptor *intf_desc;
378 int irq_interval=0;
380 dbg ("(mdc800_usb_probe) called.");
383 if (mdc800->dev != 0)
385 warn ("only one Mustek MDC800 is supported.");
386 return 0;
389 if (dev->descriptor.bNumConfigurations != 1)
391 err ("probe fails -> wrong Number of Configuration");
392 return 0;
394 intf_desc=&dev->actconfig->interface[ifnum].altsetting[0];
396 if (
397 ( intf_desc->bInterfaceClass != 0xff )
398 || ( intf_desc->bInterfaceSubClass != 0 )
399 || ( intf_desc->bInterfaceProtocol != 0 )
400 || ( intf_desc->bNumEndpoints != 4)
403 err ("probe fails -> wrong Interface");
404 return 0;
407 /* Check the Endpoints */
408 for (i=0; i<4; i++)
410 mdc800->endpoint[i]=-1;
411 for (j=0; j<4; j++)
413 if (mdc800_endpoint_equals (&intf_desc->endpoint [j],&mdc800_ed [i]))
415 mdc800->endpoint[i]=intf_desc->endpoint [j].bEndpointAddress ;
416 if (i==1)
418 irq_interval=intf_desc->endpoint [j].bInterval;
421 continue;
424 if (mdc800->endpoint[i] == -1)
426 err ("probe fails -> Wrong Endpoints.");
427 return 0;
432 usb_driver_claim_interface (&mdc800_usb_driver, &dev->actconfig->interface[ifnum], mdc800);
433 if (usb_set_interface (dev, ifnum, 0) < 0)
435 err ("MDC800 Configuration fails.");
436 return 0;
439 info ("Found Mustek MDC800 on USB.");
441 spin_lock (&mdc800->io_lock);
443 mdc800->dev=dev;
444 mdc800->open=0;
446 /* Setup URB Structs */
447 FILL_INT_URB (
448 mdc800->irq_urb,
449 mdc800->dev,
450 usb_rcvintpipe (mdc800->dev,mdc800->endpoint [1]),
451 mdc800->irq_urb_buffer,
453 mdc800_usb_irq,
454 mdc800,
455 irq_interval
458 FILL_BULK_URB (
459 mdc800->write_urb,
460 mdc800->dev,
461 usb_sndbulkpipe (mdc800->dev, mdc800->endpoint[0]),
462 mdc800->write_urb_buffer,
464 mdc800_usb_write_notify,
465 mdc800
468 FILL_BULK_URB (
469 mdc800->download_urb,
470 mdc800->dev,
471 usb_rcvbulkpipe (mdc800->dev, mdc800->endpoint [3]),
472 mdc800->download_urb_buffer,
474 mdc800_usb_download_notify,
475 mdc800
478 mdc800->state=READY;
480 spin_unlock (&mdc800->io_lock);
482 return mdc800;
487 * Disconnect USB device (maybe the MDC800)
489 static void mdc800_usb_disconnect (struct usb_device *dev,void* ptr)
491 struct mdc800_data* mdc800=(struct mdc800_data*) ptr;
493 dbg ("(mdc800_usb_disconnect) called");
495 if (mdc800->state == NOT_CONNECTED)
496 return;
498 mdc800->state=NOT_CONNECTED;
500 usb_unlink_urb (mdc800->irq_urb);
501 usb_unlink_urb (mdc800->write_urb);
502 usb_unlink_urb (mdc800->download_urb);
504 usb_driver_release_interface (&mdc800_usb_driver, &dev->actconfig->interface[1]);
506 mdc800->dev=0;
507 info ("Mustek MDC800 disconnected from USB.");
511 /***************************************************************************
512 The Misc device Part (file_operations)
513 ****************************************************************************/
516 * This Function calc the Answersize for a command.
518 static int mdc800_getAnswerSize (char command)
520 switch ((unsigned char) command)
522 case 0x2a:
523 case 0x49:
524 case 0x51:
525 case 0x0d:
526 case 0x20:
527 case 0x07:
528 case 0x01:
529 case 0x25:
530 case 0x00:
531 return 8;
533 case 0x05:
534 case 0x3e:
535 return mdc800->pic_len;
537 case 0x09:
538 return 4096;
540 default:
541 return 0;
547 * Init the device: (1) alloc mem (2) Increase MOD Count ..
549 static int mdc800_device_open (struct inode* inode, struct file *file)
551 int retval=0;
552 int errn=0;
554 spin_lock (&mdc800->io_lock);
556 if (mdc800->state == NOT_CONNECTED)
558 errn=-EBUSY;
559 goto error_out;
561 if (mdc800->open)
563 errn=-EBUSY;
564 goto error_out;
567 mdc800->in_count=0;
568 mdc800->out_count=0;
569 mdc800->out_ptr=0;
570 mdc800->pic_index=0;
571 mdc800->pic_len=-1;
572 mdc800->download_left=0;
574 mdc800->camera_busy=0;
575 mdc800->camera_request_ready=0;
577 retval=0;
578 mdc800->irq_urb->dev = mdc800->dev;
579 if (usb_submit_urb (mdc800->irq_urb))
581 err ("request USB irq fails (submit_retval=%i urb_status=%i).",retval, mdc800->irq_urb->status);
582 errn = -EIO;
583 goto error_out;
586 mdc800->open=1;
587 dbg ("Mustek MDC800 device opened.");
589 error_out:
590 spin_unlock (&mdc800->io_lock);
591 return errn;
596 * Close the Camera and release Memory
598 static int mdc800_device_release (struct inode* inode, struct file *file)
600 int retval=0;
601 dbg ("Mustek MDC800 device closed.");
603 spin_lock (&mdc800->io_lock);
604 if (mdc800->open && (mdc800->state != NOT_CONNECTED))
606 mdc800->open=0;
607 usb_unlink_urb (mdc800->irq_urb);
608 usb_unlink_urb (mdc800->write_urb);
609 usb_unlink_urb (mdc800->download_urb);
611 else
613 retval=-EIO;
615 spin_unlock (&mdc800->io_lock);
617 return retval;
622 * The Device read callback Function
624 static ssize_t mdc800_device_read (struct file *file, char *buf, size_t len, loff_t *pos)
626 int left=len, sts=len; /* single transfer size */
627 char* ptr=buf;
629 spin_lock (&mdc800->io_lock);
630 if (mdc800->state == NOT_CONNECTED)
632 spin_unlock (&mdc800->io_lock);
633 return -EBUSY;
635 if (mdc800->state == WORKING)
637 warn ("Illegal State \"working\" reached during read ?!");
638 spin_unlock (&mdc800->io_lock);
639 return -EBUSY;
641 if (!mdc800->open)
643 spin_unlock (&mdc800->io_lock);
644 return -EBUSY;
647 while (left)
649 if (signal_pending (current))
651 spin_unlock (&mdc800->io_lock);
652 return -EINTR;
655 sts=left > (mdc800->out_count-mdc800->out_ptr)?mdc800->out_count-mdc800->out_ptr:left;
657 if (sts <= 0)
659 /* Too less Data in buffer */
660 if (mdc800->state == DOWNLOAD)
662 mdc800->out_count=0;
663 mdc800->out_ptr=0;
665 /* Download -> Request new bytes */
666 mdc800->download_urb->dev = mdc800->dev;
667 if (usb_submit_urb (mdc800->download_urb))
669 err ("Can't submit download urb (status=%i)",mdc800->download_urb->status);
670 spin_unlock (&mdc800->io_lock);
671 return len-left;
673 interruptible_sleep_on_timeout (&mdc800->download_wait, TO_DOWNLOAD_GET_READY*HZ/1000);
674 if (mdc800->download_urb->status != 0)
676 err ("request download-bytes fails (status=%i)",mdc800->download_urb->status);
677 spin_unlock (&mdc800->io_lock);
678 return len-left;
681 else
683 /* No more bytes -> that's an error*/
684 spin_unlock (&mdc800->io_lock);
685 return -EIO;
688 else
690 /* memcpy Bytes */
691 memcpy (ptr, &mdc800->out [mdc800->out_ptr], sts);
692 ptr+=sts;
693 left-=sts;
694 mdc800->out_ptr+=sts;
698 spin_unlock (&mdc800->io_lock);
699 return len-left;
704 * The Device write callback Function
705 * If a 8Byte Command is received, it will be send to the camera.
706 * After this the driver initiates the request for the answer or
707 * just waits until the camera becomes ready.
709 static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t len, loff_t *pos)
711 int i=0;
713 spin_lock (&mdc800->io_lock);
714 if (mdc800->state != READY)
716 spin_unlock (&mdc800->io_lock);
717 return -EBUSY;
719 if (!mdc800->open )
721 spin_unlock (&mdc800->io_lock);
722 return -EBUSY;
725 while (i<len)
727 if (signal_pending (current))
729 spin_unlock (&mdc800->io_lock);
730 return -EINTR;
733 /* check for command start */
734 if (buf [i] == (char) 0x55)
736 mdc800->in_count=0;
737 mdc800->out_count=0;
738 mdc800->out_ptr=0;
739 mdc800->download_left=0;
742 /* save command byte */
743 if (mdc800->in_count < 8)
745 mdc800->in[mdc800->in_count]=buf[i];
746 mdc800->in_count++;
748 else
750 err ("Command is to long !\n");
751 spin_unlock (&mdc800->io_lock);
752 return -EIO;
755 /* Command Buffer full ? -> send it to camera */
756 if (mdc800->in_count == 8)
758 int answersize;
760 if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
762 err ("Camera didn't get ready.\n");
763 spin_unlock (&mdc800->io_lock);
764 return -EIO;
767 answersize=mdc800_getAnswerSize (mdc800->in[1]);
769 mdc800->state=WORKING;
770 memcpy (mdc800->write_urb->transfer_buffer, mdc800->in,8);
771 mdc800->write_urb->dev = mdc800->dev;
772 if (usb_submit_urb (mdc800->write_urb))
774 err ("submitting write urb fails (status=%i)", mdc800->write_urb->status);
775 spin_unlock (&mdc800->io_lock);
776 return -EIO;
778 interruptible_sleep_on_timeout (&mdc800->write_wait, TO_WRITE_GET_READY*HZ/1000);
779 if (mdc800->state == WORKING)
781 usb_unlink_urb (mdc800->write_urb);
782 spin_unlock (&mdc800->io_lock);
783 return -EIO;
786 switch ((unsigned char) mdc800->in[1])
788 case 0x05: /* Download Image */
789 case 0x3e: /* Take shot in Fine Mode (WCam Mode) */
790 if (mdc800->pic_len < 0)
792 err ("call 0x07 before 0x05,0x3e");
793 mdc800->state=READY;
794 spin_unlock (&mdc800->io_lock);
795 return -EIO;
797 mdc800->pic_len=-1;
799 case 0x09: /* Download Thumbnail */
800 mdc800->download_left=answersize+64;
801 mdc800->state=DOWNLOAD;
802 mdc800_usb_waitForIRQ (0,TO_DOWNLOAD_GET_BUSY);
803 break;
806 default:
807 if (answersize)
810 if (mdc800_usb_waitForIRQ (1,TO_READ_FROM_IRQ))
812 err ("requesting answer from irq fails");
813 spin_unlock (&mdc800->io_lock);
814 return -EIO;
817 /* Write dummy data, (this is ugly but part of the USB Protokoll */
818 /* if you use endpoint 1 as bulk and not as irq */
819 memcpy (mdc800->out, mdc800->camera_response,8);
821 /* This is the interpreted answer */
822 memcpy (&mdc800->out[8], mdc800->camera_response,8);
824 mdc800->out_ptr=0;
825 mdc800->out_count=16;
827 /* Cache the Imagesize, if command was getImageSize */
828 if (mdc800->in [1] == (char) 0x07)
830 mdc800->pic_len=(int) 65536*(unsigned char) mdc800->camera_response[0]+256*(unsigned char) mdc800->camera_response[1]+(unsigned char) mdc800->camera_response[2];
832 dbg ("cached imagesize = %i",mdc800->pic_len);
836 else
838 if (mdc800_usb_waitForIRQ (0,TO_DEFAULT_COMMAND))
840 err ("Command Timeout.");
841 spin_unlock (&mdc800->io_lock);
842 return -EIO;
845 mdc800->state=READY;
846 break;
849 i++;
851 spin_unlock (&mdc800->io_lock);
852 return i;
856 /***************************************************************************
857 Init and Cleanup this driver (Structs and types)
858 ****************************************************************************/
860 /* File Operations of this drivers */
861 static struct file_operations mdc800_device_ops =
863 owner: THIS_MODULE,
864 read: mdc800_device_read,
865 write: mdc800_device_write,
866 open: mdc800_device_open,
867 release: mdc800_device_release,
872 static struct usb_device_id mdc800_table [] = {
873 { idVendor: MDC800_VENDOR_ID, idProduct: MDC800_PRODUCT_ID },
874 { } /* Terminating entry */
877 MODULE_DEVICE_TABLE (usb, mdc800_table);
879 * USB Driver Struct for this device
881 static struct usb_driver mdc800_usb_driver =
883 name: "mdc800",
884 probe: mdc800_usb_probe,
885 disconnect: mdc800_usb_disconnect,
886 fops: &mdc800_device_ops,
887 minor: MDC800_DEVICE_MINOR_BASE,
888 id_table: mdc800_table
893 /************************************************************************
894 Init and Cleanup this driver (Main Functions)
895 *************************************************************************/
897 #define try(A) if ((A) == 0) goto cleanup_on_fail;
898 #define try_free_mem(A) if (A != 0) { kfree (A); A=0; }
899 #define try_free_urb(A) if (A != 0) { usb_free_urb (A); A=0; }
901 int __init usb_mdc800_init (void)
903 /* Allocate Memory */
904 try (mdc800=kmalloc (sizeof (struct mdc800_data), GFP_KERNEL));
906 memset(mdc800, 0, sizeof(struct mdc800_data));
907 mdc800->dev=0;
908 mdc800->open=0;
909 mdc800->state=NOT_CONNECTED;
910 spin_lock_init (&mdc800->io_lock);
912 init_waitqueue_head (&mdc800->irq_wait);
913 init_waitqueue_head (&mdc800->write_wait);
914 init_waitqueue_head (&mdc800->download_wait);
916 try (mdc800->irq_urb_buffer=kmalloc (8, GFP_KERNEL));
917 try (mdc800->write_urb_buffer=kmalloc (8, GFP_KERNEL));
918 try (mdc800->download_urb_buffer=kmalloc (64, GFP_KERNEL));
920 try (mdc800->irq_urb=usb_alloc_urb (0));
921 try (mdc800->download_urb=usb_alloc_urb (0));
922 try (mdc800->write_urb=usb_alloc_urb (0));
924 /* Register the driver */
925 if (usb_register (&mdc800_usb_driver) < 0)
926 goto cleanup_on_fail;
928 info ("Mustek Digital Camera Driver " VERSION " (MDC800)");
929 info (RELEASE_DATE " Henning Zabel <henning@uni-paderborn.de>");
931 return 0;
933 /* Clean driver up, when something fails */
935 cleanup_on_fail:
937 if (mdc800 != 0)
939 err ("can't alloc memory!");
941 try_free_mem (mdc800->download_urb_buffer);
942 try_free_mem (mdc800->write_urb_buffer);
943 try_free_mem (mdc800->irq_urb_buffer);
945 try_free_urb (mdc800->write_urb);
946 try_free_urb (mdc800->download_urb);
947 try_free_urb (mdc800->irq_urb);
949 kfree (mdc800);
951 mdc800=0;
952 return -1;
956 void __exit usb_mdc800_cleanup (void)
958 usb_deregister (&mdc800_usb_driver);
960 usb_free_urb (mdc800->irq_urb);
961 usb_free_urb (mdc800->download_urb);
962 usb_free_urb (mdc800->write_urb);
964 kfree (mdc800->irq_urb_buffer);
965 kfree (mdc800->write_urb_buffer);
966 kfree (mdc800->download_urb_buffer);
968 kfree (mdc800);
969 mdc800=0;
973 MODULE_AUTHOR ("Henning Zabel <henning@uni-paderborn.de>");
974 MODULE_DESCRIPTION ("USB Driver for Mustek MDC800 Digital Camera");
976 module_init (usb_mdc800_init);
977 module_exit (usb_mdc800_cleanup);