88 #include <linux/sched.h>
89 #include <linux/signal.h>
91 #include <linux/errno.h>
92 #include <linux/random.h>
93 #include <linux/poll.h>
95 #include <linux/slab.h>
96 #include <linux/module.h>
97 #include <linux/wait.h>
101 #include <linux/fs.h>
106 #define DRIVER_VERSION "v0.7.5 (30/10/2000)"
108 #define DRIVER_DESC "USB Driver for Mustek MDC800 Digital Camera"
111 #define MDC800_VENDOR_ID 0x055f
112 #define MDC800_PRODUCT_ID 0xa800
115 #define TO_DOWNLOAD_GET_READY 1500
116 #define TO_DOWNLOAD_GET_BUSY 1500
117 #define TO_WRITE_GET_READY 1000
118 #define TO_DEFAULT_COMMAND 5000
119 #define TO_READ_FROM_IRQ TO_DEFAULT_COMMAND
120 #define TO_GET_READY TO_DEFAULT_COMMAND
123 #define MDC800_DEVICE_MINOR_BASE 32
188 .bDescriptorType = 0,
189 .bEndpointAddress = 0x01,
190 .bmAttributes = 0x02,
198 .bDescriptorType = 0,
199 .bEndpointAddress = 0x82,
200 .bmAttributes = 0x03,
208 .bDescriptorType = 0,
209 .bEndpointAddress = 0x03,
210 .bmAttributes = 0x02,
218 .bDescriptorType = 0,
219 .bEndpointAddress = 0x84,
220 .bmAttributes = 0x02,
249 static int mdc800_isBusy (
char* ch)
254 if (ch [i] != (
char)0x99)
265 static int mdc800_isReady (
char *ch)
270 if (ch [i] != (
char)0xbb)
282 static void mdc800_usb_irq (
struct urb *
urb)
285 unsigned char* b=urb->transfer_buffer;
291 if (mdc800_isBusy (b))
307 if (!(mdc800_isBusy (b) || mdc800_isReady (b)))
310 dev_dbg(dev,
"%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]);
346 static int mdc800_usb_waitForIRQ (
int mode,
int msec)
356 dev_err(&mdc800->
dev->dev,
"timeout waiting for camera.\n");
363 "during waiting for irq.\n");
375 static void mdc800_usb_write_notify (
struct urb *urb)
378 int status = urb->status;
382 "writing command fails (status=%i)\n", status);
393 static void mdc800_usb_download_notify (
struct urb *urb)
396 int status = urb->status;
400 memcpy (mdc800->
out, urb->transfer_buffer, 64);
410 "request bytes fails (status:%i)\n", status);
421 static struct usb_driver mdc800_usb_driver;
423 static struct usb_class_driver mdc800_class = {
425 .fops = &mdc800_device_ops,
437 struct usb_host_interface *intf_desc;
438 struct usb_device *dev = interface_to_usbdev (intf);
442 dev_dbg(&intf->dev,
"(%s) called.\n", __func__);
447 dev_warn(&intf->dev,
"only one Mustek MDC800 is supported.\n");
451 if (dev->descriptor.bNumConfigurations != 1)
454 "probe fails -> wrong Number of Configuration\n");
457 intf_desc = intf->cur_altsetting;
460 ( intf_desc->desc.bInterfaceClass != 0xff )
461 || ( intf_desc->desc.bInterfaceSubClass != 0 )
462 || ( intf_desc->desc.bInterfaceProtocol != 0 )
463 || ( intf_desc->desc.bNumEndpoints != 4)
466 dev_err(&intf->dev,
"probe fails -> wrong Interface\n");
476 if (mdc800_endpoint_equals (&intf_desc->endpoint [j].desc,&mdc800_ed [i]))
478 mdc800->
endpoint[
i]=intf_desc->endpoint [
j].desc.bEndpointAddress ;
481 irq_interval=intf_desc->endpoint [
j].desc.bInterval;
487 dev_err(&intf->dev,
"probe fails -> Wrong Endpoints.\n");
493 dev_info(&intf->dev,
"Found Mustek MDC800 on USB.\n");
499 dev_err(&intf->dev,
"Not able to get a minor for this device.\n");
522 usb_sndbulkpipe (mdc800->
dev, mdc800->
endpoint[0]),
525 mdc800_usb_write_notify,
532 usb_rcvbulkpipe (mdc800->
dev, mdc800->
endpoint [3]),
535 mdc800_usb_download_notify,
543 usb_set_intfdata(intf, mdc800);
551 static void mdc800_usb_disconnect (
struct usb_interface *intf)
553 struct mdc800_data* mdc800 = usb_get_intfdata(intf);
555 dev_dbg(&intf->dev,
"(%s) called\n", __func__);
574 usb_set_intfdata(intf,
NULL);
576 dev_info(&intf->dev,
"Mustek MDC800 disconnected from USB.\n");
587 static int mdc800_getAnswerSize (
char command)
589 switch ((
unsigned char) command)
651 "request USB irq fails (submit_retval=%i).\n", retval);
657 dev_dbg(&mdc800->
dev->dev,
"Mustek MDC800 device opened.\n");
668 static int mdc800_device_release (
struct inode* inode,
struct file *file)
693 static ssize_t mdc800_device_read (
struct file *file,
char __user *
buf,
size_t len, loff_t *
pos)
708 "reached during read ?!\n");
741 "Can't submit download urb "
742 "(retval=%i)\n", retval);
752 "request download-bytes fails "
791 static ssize_t mdc800_device_write (
struct file *file,
const char __user *buf,
size_t len, loff_t *pos)
852 "Camera didn't get ready.\n");
857 answersize=mdc800_getAnswerSize (mdc800->
in[1]);
865 "submitting write urb fails "
866 "(retval=%i)\n", retval);
879 switch ((
unsigned char) mdc800->
in[1])
907 dev_err(&mdc800->
dev->dev,
"requesting answer from irq fails\n");
923 if (mdc800->
in [1] == (
char) 0x07)
935 dev_err(&mdc800->
dev->dev,
"Command Timeout.\n");
959 .read = mdc800_device_read,
960 .write = mdc800_device_write,
961 .open = mdc800_device_open,
962 .release = mdc800_device_release,
977 static struct usb_driver mdc800_usb_driver =
980 .probe = mdc800_usb_probe,
981 .disconnect = mdc800_usb_disconnect,
982 .id_table = mdc800_table
991 static int __init usb_mdc800_init (
void)
997 goto cleanup_on_fail;
1013 goto cleanup_on_fail;
1016 goto cleanup_on_fail;
1019 goto cleanup_on_fail;
1023 goto cleanup_on_fail;
1026 goto cleanup_on_fail;
1029 goto cleanup_on_fail;
1032 retval = usb_register(&mdc800_usb_driver);
1034 goto cleanup_on_fail;
1064 static void __exit usb_mdc800_cleanup (
void)