2 * adutux - driver for ADU devices from Ontrak Control Systems
3 * This is an experimental driver. Use at your own risk.
4 * This driver is not supported by Ontrak Control Systems.
6 * Copyright (c) 2003 John Homppi (SCO, leave this notice here)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * derived from the Lego USB Tower driver 0.56:
14 * Copyright (c) 2003 David Glance <davidgsf@sourceforge.net>
15 * 2001 Juergen Stuber <stuber@loria.fr>
16 * that was derived from USB Skeleton driver - 0.5
17 * Copyright (c) 2001 Greg Kroah-Hartman (greg@kroah.com)
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/usb.h>
27 #include <asm/uaccess.h>
29 #ifdef CONFIG_USB_DEBUG
35 /* Use our own dbg macro */
37 #define dbg(lvl, format, arg...) \
40 printk(KERN_DEBUG __FILE__ " : " format " \n", ## arg); \
44 /* Version Information */
45 #define DRIVER_VERSION "v0.0.13"
46 #define DRIVER_AUTHOR "John Homppi"
47 #define DRIVER_DESC "adutux (see www.ontrak.net)"
49 /* Module parameters */
50 module_param(debug, int, S_IRUGO | S_IWUSR);
51 MODULE_PARM_DESC(debug, "Debug enabled or not");
53 /* Define these values to match your device */
54 #define ADU_VENDOR_ID 0x0a07
55 #define ADU_PRODUCT_ID 0x0064
57 /* table of devices that work with this driver */
58 static struct usb_device_id device_table [] = {
59 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID) }, /* ADU100 */
60 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+20) }, /* ADU120 */
61 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+30) }, /* ADU130 */
62 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+100) }, /* ADU200 */
63 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+108) }, /* ADU208 */
64 { USB_DEVICE(ADU_VENDOR_ID, ADU_PRODUCT_ID+118) }, /* ADU218 */
65 { }/* Terminating entry */
68 MODULE_DEVICE_TABLE(usb, device_table);
70 #ifdef CONFIG_USB_DYNAMIC_MINORS
71 #define ADU_MINOR_BASE 0
73 #define ADU_MINOR_BASE 67
76 /* we can have up to this number of device plugged in at once */
77 #define MAX_DEVICES 16
79 #define COMMAND_TIMEOUT (2*HZ) /* 60 second timeout for a command */
81 /* Structure to hold all of our device specific stuff */
83 struct semaphore sem; /* locks this structure */
84 struct usb_device* udev; /* save off the usb device pointer */
85 struct usb_interface* interface;
86 unsigned char minor; /* the starting minor number for this device */
87 char serial_number[8];
89 int open_count; /* number of times this port has been opened */
91 char* read_buffer_primary;
92 int read_buffer_length;
93 char* read_buffer_secondary;
98 wait_queue_head_t read_wait;
99 wait_queue_head_t write_wait;
101 char* interrupt_in_buffer;
102 struct usb_endpoint_descriptor* interrupt_in_endpoint;
103 struct urb* interrupt_in_urb;
104 int read_urb_finished;
106 char* interrupt_out_buffer;
107 struct usb_endpoint_descriptor* interrupt_out_endpoint;
108 struct urb* interrupt_out_urb;
111 /* prevent races between open() and disconnect */
112 static DEFINE_MUTEX(disconnect_mutex);
113 static struct usb_driver adu_driver;
115 static void adu_debug_data(int level, const char *function, int size,
116 const unsigned char *data)
123 printk(KERN_DEBUG __FILE__": %s - length = %d, data = ",
125 for (i = 0; i < size; ++i)
126 printk("%.2x ", data[i]);
131 * adu_abort_transfers
132 * aborts transfers and frees associated data structures
134 static void adu_abort_transfers(struct adu_device *dev)
136 dbg(2," %s : enter", __FUNCTION__);
139 dbg(1," %s : dev is null", __FUNCTION__);
143 if (dev->udev == NULL) {
144 dbg(1," %s : udev is null", __FUNCTION__);
148 dbg(2," %s : udev state %d", __FUNCTION__, dev->udev->state);
149 if (dev->udev->state == USB_STATE_NOTATTACHED) {
150 dbg(1," %s : udev is not attached", __FUNCTION__);
154 /* shutdown transfer */
155 usb_unlink_urb(dev->interrupt_in_urb);
156 usb_unlink_urb(dev->interrupt_out_urb);
159 dbg(2," %s : leave", __FUNCTION__);
162 static void adu_delete(struct adu_device *dev)
164 dbg(2, "%s enter", __FUNCTION__);
166 adu_abort_transfers(dev);
168 /* free data structures */
169 usb_free_urb(dev->interrupt_in_urb);
170 usb_free_urb(dev->interrupt_out_urb);
171 kfree(dev->read_buffer_primary);
172 kfree(dev->read_buffer_secondary);
173 kfree(dev->interrupt_in_buffer);
174 kfree(dev->interrupt_out_buffer);
177 dbg(2, "%s : leave", __FUNCTION__);
180 static void adu_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
182 struct adu_device *dev = urb->context;
184 dbg(4," %s : enter, status %d", __FUNCTION__, urb->status);
185 adu_debug_data(5, __FUNCTION__, urb->actual_length,
186 urb->transfer_buffer);
188 spin_lock(&dev->buflock);
190 if (urb->status != 0) {
191 if ((urb->status != -ENOENT) && (urb->status != -ECONNRESET)) {
192 dbg(1," %s : nonzero status received: %d",
193 __FUNCTION__, urb->status);
198 if (urb->actual_length > 0 && dev->interrupt_in_buffer[0] != 0x00) {
199 if (dev->read_buffer_length <
200 (4 * le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize)) -
201 (urb->actual_length)) {
202 memcpy (dev->read_buffer_primary +
203 dev->read_buffer_length,
204 dev->interrupt_in_buffer, urb->actual_length);
206 dev->read_buffer_length += urb->actual_length;
207 dbg(2," %s reading %d ", __FUNCTION__,
210 dbg(1," %s : read_buffer overflow", __FUNCTION__);
215 dev->read_urb_finished = 1;
216 spin_unlock(&dev->buflock);
217 /* always wake up so we recover from errors */
218 wake_up_interruptible(&dev->read_wait);
219 adu_debug_data(5, __FUNCTION__, urb->actual_length,
220 urb->transfer_buffer);
221 dbg(4," %s : leave, status %d", __FUNCTION__, urb->status);
224 static void adu_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
226 struct adu_device *dev = urb->context;
228 dbg(4," %s : enter, status %d", __FUNCTION__, urb->status);
229 adu_debug_data(5,__FUNCTION__, urb->actual_length, urb->transfer_buffer);
231 if (urb->status != 0) {
232 if ((urb->status != -ENOENT) &&
233 (urb->status != -ECONNRESET)) {
234 dbg(1, " %s :nonzero status received: %d",
235 __FUNCTION__, urb->status);
240 wake_up_interruptible(&dev->write_wait);
243 adu_debug_data(5, __FUNCTION__, urb->actual_length,
244 urb->transfer_buffer);
245 dbg(4," %s : leave, status %d", __FUNCTION__, urb->status);
248 static int adu_open(struct inode *inode, struct file *file)
250 struct adu_device *dev = NULL;
251 struct usb_interface *interface;
255 dbg(2,"%s : enter", __FUNCTION__);
257 subminor = iminor(inode);
259 mutex_lock(&disconnect_mutex);
261 interface = usb_find_interface(&adu_driver, subminor);
263 err("%s - error, can't find device for minor %d",
264 __FUNCTION__, subminor);
269 dev = usb_get_intfdata(interface);
275 /* lock this device */
276 if ((retval = down_interruptible(&dev->sem))) {
277 dbg(2, "%s : sem down failed", __FUNCTION__);
281 /* increment our usage count for the device */
283 dbg(2,"%s : open count %d", __FUNCTION__, dev->open_count);
285 /* save device in the file's private structure */
286 file->private_data = dev;
288 /* initialize in direction */
289 dev->read_buffer_length = 0;
291 /* fixup first read by having urb waiting for it */
292 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
293 usb_rcvintpipe(dev->udev,
294 dev->interrupt_in_endpoint->bEndpointAddress),
295 dev->interrupt_in_buffer,
296 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
297 adu_interrupt_in_callback, dev,
298 dev->interrupt_in_endpoint->bInterval);
299 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
300 dev->read_urb_finished = 0;
301 usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
302 /* we ignore failure */
303 /* end of fixup for first read */
308 mutex_unlock(&disconnect_mutex);
309 dbg(2,"%s : leave, return value %d ", __FUNCTION__, retval);
314 static int adu_release_internal(struct adu_device *dev)
318 dbg(2," %s : enter", __FUNCTION__);
320 if (dev->udev == NULL) {
321 /* the device was unplugged before the file was released */
326 /* decrement our usage count for the device */
328 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
329 if (dev->open_count <= 0) {
330 adu_abort_transfers(dev);
335 dbg(2," %s : leave", __FUNCTION__);
339 static int adu_release(struct inode *inode, struct file *file)
341 struct adu_device *dev = NULL;
344 dbg(2," %s : enter", __FUNCTION__);
347 dbg(1," %s : file is NULL", __FUNCTION__);
352 dev = file->private_data;
355 dbg(1," %s : object is NULL", __FUNCTION__);
360 /* lock our device */
361 down(&dev->sem); /* not interruptible */
363 if (dev->open_count <= 0) {
364 dbg(1," %s : device not opened", __FUNCTION__);
370 retval = adu_release_internal(dev);
374 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
378 static ssize_t adu_read(struct file *file, __user char *buffer, size_t count,
381 struct adu_device *dev;
382 size_t bytes_read = 0;
383 size_t bytes_to_read = count;
387 int should_submit = 0;
389 DECLARE_WAITQUEUE(wait, current);
391 dbg(2," %s : enter, count = %Zd, file=%p", __FUNCTION__, count, file);
393 dev = file->private_data;
394 dbg(2," %s : dev=%p", __FUNCTION__, dev);
395 /* lock this object */
396 if (down_interruptible(&dev->sem))
399 /* verify that the device wasn't unplugged */
400 if (dev->udev == NULL || dev->minor == 0) {
402 err("No device or device unplugged %d", retval);
406 /* verify that some data was requested */
408 dbg(1," %s : read request of 0 bytes", __FUNCTION__);
412 timeout = COMMAND_TIMEOUT;
413 dbg(2," %s : about to start looping", __FUNCTION__);
414 while (bytes_to_read) {
415 int data_in_secondary = dev->secondary_tail - dev->secondary_head;
416 dbg(2," %s : while, data_in_secondary=%d, status=%d",
417 __FUNCTION__, data_in_secondary,
418 dev->interrupt_in_urb->status);
420 if (data_in_secondary) {
421 /* drain secondary buffer */
422 int amount = bytes_to_read < data_in_secondary ? bytes_to_read : data_in_secondary;
423 i = copy_to_user(buffer, dev->read_buffer_secondary+dev->secondary_head, amount);
428 dev->secondary_head += (amount - i);
429 bytes_read += (amount - i);
430 bytes_to_read -= (amount - i);
432 retval = bytes_read ? bytes_read : -EFAULT;
436 /* we check the primary buffer */
437 spin_lock_irqsave (&dev->buflock, flags);
438 if (dev->read_buffer_length) {
439 /* we secure access to the primary */
441 dbg(2," %s : swap, read_buffer_length = %d",
442 __FUNCTION__, dev->read_buffer_length);
443 tmp = dev->read_buffer_secondary;
444 dev->read_buffer_secondary = dev->read_buffer_primary;
445 dev->read_buffer_primary = tmp;
446 dev->secondary_head = 0;
447 dev->secondary_tail = dev->read_buffer_length;
448 dev->read_buffer_length = 0;
449 spin_unlock_irqrestore(&dev->buflock, flags);
450 /* we have a free buffer so use it */
453 /* even the primary was empty - we may need to do IO */
454 if (dev->interrupt_in_urb->status == -EINPROGRESS) {
455 /* somebody is doing IO */
456 spin_unlock_irqrestore(&dev->buflock, flags);
457 dbg(2," %s : submitted already", __FUNCTION__);
459 /* we must initiate input */
460 dbg(2," %s : initiate input", __FUNCTION__);
461 dev->read_urb_finished = 0;
463 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
464 usb_rcvintpipe(dev->udev,
465 dev->interrupt_in_endpoint->bEndpointAddress),
466 dev->interrupt_in_buffer,
467 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
468 adu_interrupt_in_callback,
470 dev->interrupt_in_endpoint->bInterval);
471 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
473 spin_unlock_irqrestore(&dev->buflock, flags);
474 dbg(2," %s : submitted OK", __FUNCTION__);
476 if (retval == -ENOMEM) {
477 retval = bytes_read ? bytes_read : -ENOMEM;
479 spin_unlock_irqrestore(&dev->buflock, flags);
480 dbg(2," %s : submit failed", __FUNCTION__);
485 /* we wait for I/O to complete */
486 set_current_state(TASK_INTERRUPTIBLE);
487 add_wait_queue(&dev->read_wait, &wait);
488 if (!dev->read_urb_finished)
489 timeout = schedule_timeout(COMMAND_TIMEOUT);
491 set_current_state(TASK_RUNNING);
492 remove_wait_queue(&dev->read_wait, &wait);
495 dbg(2," %s : timeout", __FUNCTION__);
496 retval = bytes_read ? bytes_read : -ETIMEDOUT;
500 if (signal_pending(current)) {
501 dbg(2," %s : signal pending", __FUNCTION__);
502 retval = bytes_read ? bytes_read : -EINTR;
510 /* if the primary buffer is empty then use it */
511 if (should_submit && !dev->interrupt_in_urb->status==-EINPROGRESS) {
512 usb_fill_int_urb(dev->interrupt_in_urb,dev->udev,
513 usb_rcvintpipe(dev->udev,
514 dev->interrupt_in_endpoint->bEndpointAddress),
515 dev->interrupt_in_buffer,
516 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize),
517 adu_interrupt_in_callback,
519 dev->interrupt_in_endpoint->bInterval);
520 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
521 dev->read_urb_finished = 0;
522 usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
523 /* we ignore failure */
527 /* unlock the device */
530 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
534 static ssize_t adu_write(struct file *file, const __user char *buffer,
535 size_t count, loff_t *ppos)
537 struct adu_device *dev;
538 size_t bytes_written = 0;
539 size_t bytes_to_write;
544 dbg(2," %s : enter, count = %Zd", __FUNCTION__, count);
546 dev = file->private_data;
548 /* lock this object */
549 down_interruptible(&dev->sem);
551 /* verify that the device wasn't unplugged */
552 if (dev->udev == NULL || dev->minor == 0) {
554 err("No device or device unplugged %d", retval);
558 /* verify that we actually have some data to write */
560 dbg(1," %s : write request of 0 bytes", __FUNCTION__);
566 if (dev->interrupt_out_urb->status == -EINPROGRESS) {
567 timeout = COMMAND_TIMEOUT;
569 while (timeout > 0) {
570 if (signal_pending(current)) {
571 dbg(1," %s : interrupted", __FUNCTION__);
576 timeout = interruptible_sleep_on_timeout(&dev->write_wait, timeout);
577 down_interruptible(&dev->sem);
581 dbg(1," %s : interrupted timeout: %d", __FUNCTION__, timeout);
585 dbg(1," %s : final timeout: %d", __FUNCTION__, timeout);
588 dbg(1, "%s - command timed out.", __FUNCTION__);
593 dbg(4," %s : in progress, count = %Zd", __FUNCTION__, count);
596 dbg(4," %s : sending, count = %Zd", __FUNCTION__, count);
598 /* write the data into interrupt_out_buffer from userspace */
599 buffer_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);
600 bytes_to_write = count > buffer_size ? buffer_size : count;
601 dbg(4," %s : buffer_size = %Zd, count = %Zd, bytes_to_write = %Zd",
602 __FUNCTION__, buffer_size, count, bytes_to_write);
604 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write) != 0) {
609 /* send off the urb */
611 dev->interrupt_out_urb,
613 usb_sndintpipe(dev->udev, dev->interrupt_out_endpoint->bEndpointAddress),
614 dev->interrupt_out_buffer,
616 adu_interrupt_out_callback,
618 dev->interrupt_in_endpoint->bInterval);
619 /* dev->interrupt_in_urb->transfer_flags |= URB_ASYNC_UNLINK; */
620 dev->interrupt_out_urb->actual_length = bytes_to_write;
621 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
623 err("Couldn't submit interrupt_out_urb %d", retval);
627 buffer += bytes_to_write;
628 count -= bytes_to_write;
630 bytes_written += bytes_to_write;
634 retval = bytes_written;
637 /* unlock the device */
640 dbg(2," %s : leave, return value %d", __FUNCTION__, retval);
645 /* file operations needed when we register this driver */
646 static struct file_operations adu_fops = {
647 .owner = THIS_MODULE,
651 .release = adu_release,
655 * usb class driver info in order to get a minor number from the usb core,
656 * and to have the device registered with devfs and the driver core
658 static struct usb_class_driver adu_class = {
659 .name = "usb/adutux%d",
661 .minor_base = ADU_MINOR_BASE,
667 * Called by the usb core when a new device is connected that it thinks
668 * this driver might be interested in.
670 static int adu_probe(struct usb_interface *interface,
671 const struct usb_device_id *id)
673 struct usb_device *udev = interface_to_usbdev(interface);
674 struct adu_device *dev = NULL;
675 struct usb_host_interface *iface_desc;
676 struct usb_endpoint_descriptor *endpoint;
677 int retval = -ENODEV;
682 dbg(2," %s : enter", __FUNCTION__);
685 dev_err(&interface->dev, "udev is NULL.\n");
689 /* allocate memory for our device state and intialize it */
690 dev = kzalloc(sizeof(struct adu_device), GFP_KERNEL);
692 dev_err(&interface->dev, "Out of memory\n");
697 init_MUTEX(&dev->sem);
698 spin_lock_init(&dev->buflock);
700 init_waitqueue_head(&dev->read_wait);
701 init_waitqueue_head(&dev->write_wait);
703 iface_desc = &interface->altsetting[0];
705 /* set up the endpoint information */
706 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
707 endpoint = &iface_desc->endpoint[i].desc;
709 if (usb_endpoint_is_int_in(endpoint))
710 dev->interrupt_in_endpoint = endpoint;
712 if (usb_endpoint_is_int_out(endpoint))
713 dev->interrupt_out_endpoint = endpoint;
715 if (dev->interrupt_in_endpoint == NULL) {
716 dev_err(&interface->dev, "interrupt in endpoint not found\n");
719 if (dev->interrupt_out_endpoint == NULL) {
720 dev_err(&interface->dev, "interrupt out endpoint not found\n");
724 in_end_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
725 out_end_size = le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize);
727 dev->read_buffer_primary = kmalloc((4 * in_end_size), GFP_KERNEL);
728 if (!dev->read_buffer_primary) {
729 dev_err(&interface->dev, "Couldn't allocate read_buffer_primary\n");
734 /* debug code prime the buffer */
735 memset(dev->read_buffer_primary, 'a', in_end_size);
736 memset(dev->read_buffer_primary + in_end_size, 'b', in_end_size);
737 memset(dev->read_buffer_primary + (2 * in_end_size), 'c', in_end_size);
738 memset(dev->read_buffer_primary + (3 * in_end_size), 'd', in_end_size);
740 dev->read_buffer_secondary = kmalloc((4 * in_end_size), GFP_KERNEL);
741 if (!dev->read_buffer_secondary) {
742 dev_err(&interface->dev, "Couldn't allocate read_buffer_secondary\n");
747 /* debug code prime the buffer */
748 memset(dev->read_buffer_secondary, 'e', in_end_size);
749 memset(dev->read_buffer_secondary + in_end_size, 'f', in_end_size);
750 memset(dev->read_buffer_secondary + (2 * in_end_size), 'g', in_end_size);
751 memset(dev->read_buffer_secondary + (3 * in_end_size), 'h', in_end_size);
753 dev->interrupt_in_buffer = kmalloc(in_end_size, GFP_KERNEL);
754 if (!dev->interrupt_in_buffer) {
755 dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n");
759 /* debug code prime the buffer */
760 memset(dev->interrupt_in_buffer, 'i', in_end_size);
762 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
763 if (!dev->interrupt_in_urb) {
764 dev_err(&interface->dev, "Couldn't allocate interrupt_in_urb\n");
767 dev->interrupt_out_buffer = kmalloc(out_end_size, GFP_KERNEL);
768 if (!dev->interrupt_out_buffer) {
769 dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n");
772 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
773 if (!dev->interrupt_out_urb) {
774 dev_err(&interface->dev, "Couldn't allocate interrupt_out_urb\n");
778 if (!usb_string(udev, udev->descriptor.iSerialNumber, dev->serial_number,
779 sizeof(dev->serial_number))) {
780 dev_err(&interface->dev, "Could not retrieve serial number\n");
783 dbg(2," %s : serial_number=%s", __FUNCTION__, dev->serial_number);
785 /* we can register the device now, as it is ready */
786 usb_set_intfdata(interface, dev);
788 retval = usb_register_dev(interface, &adu_class);
791 /* something prevented us from registering this driver */
792 dev_err(&interface->dev, "Not able to get a minor for this device.\n");
793 usb_set_intfdata(interface, NULL);
797 dev->minor = interface->minor;
799 /* let the user know what node this device is now attached to */
800 dev_info(&interface->dev, "ADU%d %s now attached to /dev/usb/adutux%d",
801 udev->descriptor.idProduct, dev->serial_number,
802 (dev->minor - ADU_MINOR_BASE));
804 dbg(2," %s : leave, return value %p (dev)", __FUNCTION__, dev);
816 * Called by the usb core when the device is removed from the system.
818 static void adu_disconnect(struct usb_interface *interface)
820 struct adu_device *dev;
823 dbg(2," %s : enter", __FUNCTION__);
825 mutex_lock(&disconnect_mutex); /* not interruptible */
827 dev = usb_get_intfdata(interface);
828 usb_set_intfdata(interface, NULL);
830 down(&dev->sem); /* not interruptible */
834 /* give back our minor */
835 usb_deregister_dev(interface, &adu_class);
838 /* if the device is not opened, then we clean up right now */
839 dbg(2," %s : open count %d", __FUNCTION__, dev->open_count);
840 if (!dev->open_count) {
848 mutex_unlock(&disconnect_mutex);
850 dev_info(&interface->dev, "ADU device adutux%d now disconnected",
851 (minor - ADU_MINOR_BASE));
853 dbg(2," %s : leave", __FUNCTION__);
856 /* usb specific object needed to register this driver with the usb subsystem */
857 static struct usb_driver adu_driver = {
860 .disconnect = adu_disconnect,
861 .id_table = device_table,
864 static int __init adu_init(void)
868 dbg(2," %s : enter", __FUNCTION__);
870 /* register this driver with the USB subsystem */
871 result = usb_register(&adu_driver);
873 err("usb_register failed for the "__FILE__" driver. "
874 "Error number %d", result);
878 info("adutux " DRIVER_DESC " " DRIVER_VERSION);
879 info("adutux is an experimental driver. Use at your own risk");
882 dbg(2," %s : leave, return value %d", __FUNCTION__, result);
887 static void __exit adu_exit(void)
889 dbg(2," %s : enter", __FUNCTION__);
890 /* deregister this driver with the USB subsystem */
891 usb_deregister(&adu_driver);
892 dbg(2," %s : leave", __FUNCTION__);
895 module_init(adu_init);
896 module_exit(adu_exit);
898 MODULE_AUTHOR(DRIVER_AUTHOR);
899 MODULE_DESCRIPTION(DRIVER_DESC);
900 MODULE_LICENSE("GPL");