2 * Generic USB driver for report based interrupt in/out devices
3 * like LD Didactic's USB devices. LD Didactic's USB devices are
4 * HID devices which do not use HID report definitons (they use
5 * raw interrupt in and our reports only for communication).
7 * This driver uses a ring buffer for time critical reading of
8 * interrupt in reports and provides read and write methods for
9 * raw interrupt reports (similar to the Windows HID driver).
10 * Devices based on the book USB COMPLETE by Jan Axelson may need
11 * such a compatibility to the Windows HID driver.
13 * Copyright (C) 2005 Michael Hund <mhund@ld-didactic.de>
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * Derived from Lego USB Tower driver
21 * Copyright (C) 2003 David Glance <advidgsf@sourceforge.net>
22 * 2001-2004 Juergen Stuber <starblue@users.sourceforge.net>
24 * V0.1 (mh) Initial version
25 * V0.11 (mh) Added raw support for HID 1.0 devices (no interrupt out endpoint)
26 * V0.12 (mh) Added kmalloc check for string buffer
29 #include <linux/config.h>
30 #include <linux/kernel.h>
31 #include <linux/errno.h>
32 #include <linux/init.h>
33 #include <linux/slab.h>
34 #include <linux/module.h>
36 #include <asm/uaccess.h>
37 #include <linux/input.h>
38 #include <linux/usb.h>
39 #include <linux/poll.h>
41 /* Define these values to match your devices */
42 #define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */
43 #define USB_DEVICE_ID_CASSY 0x1000 /* USB Product ID for all CASSY-S modules */
44 #define USB_DEVICE_ID_POCKETCASSY 0x1010 /* USB Product ID for Pocket-CASSY */
45 #define USB_DEVICE_ID_MOBILECASSY 0x1020 /* USB Product ID for Mobile-CASSY */
46 #define USB_DEVICE_ID_JWM 0x1080 /* USB Product ID for Joule and Wattmeter */
47 #define USB_DEVICE_ID_DMMP 0x1081 /* USB Product ID for Digital Multimeter P (reserved) */
48 #define USB_DEVICE_ID_UMIP 0x1090 /* USB Product ID for UMI P */
49 #define USB_DEVICE_ID_VIDEOCOM 0x1200 /* USB Product ID for VideoCom */
50 #define USB_DEVICE_ID_COM3LAB 0x2000 /* USB Product ID for COM3LAB */
51 #define USB_DEVICE_ID_TELEPORT 0x2010 /* USB Product ID for Terminal Adapter */
52 #define USB_DEVICE_ID_NETWORKANALYSER 0x2020 /* USB Product ID for Network Analyser */
53 #define USB_DEVICE_ID_POWERCONTROL 0x2030 /* USB Product ID for Controlling device for Power Electronics */
55 #define USB_VENDOR_ID_VERNIER 0x08f7
56 #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
57 #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
58 #define USB_DEVICE_ID_VERNIER_SKIP 0x0003
59 #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
62 #ifdef CONFIG_USB_DYNAMIC_MINORS
63 #define USB_LD_MINOR_BASE 0
65 #define USB_LD_MINOR_BASE 176
68 /* table of devices that work with this driver */
69 static struct usb_device_id ld_usb_table [] = {
70 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_CASSY) },
71 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_POCKETCASSY) },
72 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_MOBILECASSY) },
73 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_JWM) },
74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_DMMP) },
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_UMIP) },
76 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_VIDEOCOM) },
77 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_COM3LAB) },
78 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_TELEPORT) },
79 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_NETWORKANALYSER) },
80 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_POWERCONTROL) },
81 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
82 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
83 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
84 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
85 { } /* Terminating entry */
87 MODULE_DEVICE_TABLE(usb, ld_usb_table);
88 MODULE_VERSION("V0.12");
89 MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
90 MODULE_DESCRIPTION("LD USB Driver");
91 MODULE_LICENSE("GPL");
92 MODULE_SUPPORTED_DEVICE("LD USB Devices");
94 #ifdef CONFIG_USB_DEBUG
100 /* Use our own dbg macro */
101 #define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
103 /* Module parameters */
104 module_param(debug, int, S_IRUGO | S_IWUSR);
105 MODULE_PARM_DESC(debug, "Debug enabled or not");
107 /* All interrupt in transfers are collected in a ring buffer to
108 * avoid racing conditions and get better performance of the driver.
110 static int ring_buffer_size = 128;
111 module_param(ring_buffer_size, int, 0);
112 MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
114 /* The write_buffer can contain more than one interrupt out transfer.
116 static int write_buffer_size = 10;
117 module_param(write_buffer_size, int, 0);
118 MODULE_PARM_DESC(write_buffer_size, "Write buffer size in reports");
120 /* As of kernel version 2.6.4 ehci-hcd uses an
121 * "only one interrupt transfer per frame" shortcut
122 * to simplify the scheduling of periodic transfers.
123 * This conflicts with our standard 1ms intervals for in and out URBs.
124 * We use default intervals of 2ms for in and 2ms for out transfers,
125 * which should be fast enough.
126 * Increase the interval to allow more devices that do interrupt transfers,
127 * or set to 1 to use the standard interval from the endpoint descriptors.
129 static int min_interrupt_in_interval = 2;
130 module_param(min_interrupt_in_interval, int, 0);
131 MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms");
133 static int min_interrupt_out_interval = 2;
134 module_param(min_interrupt_out_interval, int, 0);
135 MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms");
137 /* Structure to hold all of our device specific stuff */
139 struct semaphore sem; /* locks this structure */
140 struct usb_interface* intf; /* save off the usb interface pointer */
142 int open_count; /* number of times this port has been opened */
145 unsigned int ring_head;
146 unsigned int ring_tail;
148 wait_queue_head_t read_wait;
149 wait_queue_head_t write_wait;
151 char* interrupt_in_buffer;
152 struct usb_endpoint_descriptor* interrupt_in_endpoint;
153 struct urb* interrupt_in_urb;
154 int interrupt_in_interval;
155 size_t interrupt_in_endpoint_size;
156 int interrupt_in_running;
157 int interrupt_in_done;
159 char* interrupt_out_buffer;
160 struct usb_endpoint_descriptor* interrupt_out_endpoint;
161 struct urb* interrupt_out_urb;
162 int interrupt_out_interval;
163 size_t interrupt_out_endpoint_size;
164 int interrupt_out_busy;
167 /* prevent races between open() and disconnect() */
168 static DECLARE_MUTEX(disconnect_sem);
170 static struct usb_driver ld_usb_driver;
173 * ld_usb_abort_transfers
174 * aborts transfers and frees associated data structures
176 static void ld_usb_abort_transfers(struct ld_usb *dev)
178 /* shutdown transfer */
179 if (dev->interrupt_in_running) {
180 dev->interrupt_in_running = 0;
182 usb_kill_urb(dev->interrupt_in_urb);
184 if (dev->interrupt_out_busy)
186 usb_kill_urb(dev->interrupt_out_urb);
192 static void ld_usb_delete(struct ld_usb *dev)
194 ld_usb_abort_transfers(dev);
196 /* free data structures */
197 usb_free_urb(dev->interrupt_in_urb);
198 usb_free_urb(dev->interrupt_out_urb);
199 kfree(dev->ring_buffer);
200 kfree(dev->interrupt_in_buffer);
201 kfree(dev->interrupt_out_buffer);
206 * ld_usb_interrupt_in_callback
208 static void ld_usb_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
210 struct ld_usb *dev = urb->context;
211 size_t *actual_buffer;
212 unsigned int next_ring_head;
216 if (urb->status == -ENOENT ||
217 urb->status == -ECONNRESET ||
218 urb->status == -ESHUTDOWN) {
221 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
222 __FUNCTION__, urb->status);
223 goto resubmit; /* maybe we can recover */
227 if (urb->actual_length > 0) {
228 next_ring_head = (dev->ring_head+1) % ring_buffer_size;
229 if (next_ring_head != dev->ring_tail) {
230 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_head*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
231 /* actual_buffer gets urb->actual_length + interrupt_in_buffer */
232 *actual_buffer = urb->actual_length;
233 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
234 dev->ring_head = next_ring_head;
235 dbg_info(&dev->intf->dev, "%s: received %d bytes\n",
236 __FUNCTION__, urb->actual_length);
238 dev_warn(&dev->intf->dev,
239 "Ring buffer overflow, %d bytes dropped\n",
244 /* resubmit if we're still running */
245 if (dev->interrupt_in_running && dev->intf) {
246 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
248 dev_err(&dev->intf->dev,
249 "usb_submit_urb failed (%d)\n", retval);
253 dev->interrupt_in_done = 1;
254 wake_up_interruptible(&dev->read_wait);
258 * ld_usb_interrupt_out_callback
260 static void ld_usb_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
262 struct ld_usb *dev = urb->context;
264 /* sync/async unlink faults aren't errors */
265 if (urb->status && !(urb->status == -ENOENT ||
266 urb->status == -ECONNRESET ||
267 urb->status == -ESHUTDOWN))
268 dbg_info(&dev->intf->dev,
269 "%s - nonzero write interrupt status received: %d\n",
270 __FUNCTION__, urb->status);
272 dev->interrupt_out_busy = 0;
273 wake_up_interruptible(&dev->write_wait);
279 static int ld_usb_open(struct inode *inode, struct file *file)
284 struct usb_interface *interface;
286 nonseekable_open(inode, file);
287 subminor = iminor(inode);
289 down(&disconnect_sem);
291 interface = usb_find_interface(&ld_usb_driver, subminor);
294 err("%s - error, can't find device for minor %d\n",
295 __FUNCTION__, subminor);
297 goto unlock_disconnect_exit;
300 dev = usb_get_intfdata(interface);
304 goto unlock_disconnect_exit;
307 /* lock this device */
308 if (down_interruptible(&dev->sem)) {
309 retval = -ERESTARTSYS;
310 goto unlock_disconnect_exit;
313 /* allow opening only once */
314 if (dev->open_count) {
320 /* initialize in direction */
323 usb_fill_int_urb(dev->interrupt_in_urb,
324 interface_to_usbdev(interface),
325 usb_rcvintpipe(interface_to_usbdev(interface),
326 dev->interrupt_in_endpoint->bEndpointAddress),
327 dev->interrupt_in_buffer,
328 dev->interrupt_in_endpoint_size,
329 ld_usb_interrupt_in_callback,
331 dev->interrupt_in_interval);
333 dev->interrupt_in_running = 1;
334 dev->interrupt_in_done = 0;
336 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
338 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval);
339 dev->interrupt_in_running = 0;
344 /* save device in the file's private structure */
345 file->private_data = dev;
350 unlock_disconnect_exit:
359 static int ld_usb_release(struct inode *inode, struct file *file)
364 dev = file->private_data;
371 if (down_interruptible(&dev->sem)) {
372 retval = -ERESTARTSYS;
376 if (dev->open_count != 1) {
380 if (dev->intf == NULL) {
381 /* the device was unplugged before the file was released */
383 /* unlock here as ld_usb_delete frees dev */
388 /* wait until write transfer is finished */
389 if (dev->interrupt_out_busy)
390 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
391 ld_usb_abort_transfers(dev);
404 static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
407 unsigned int mask = 0;
409 dev = file->private_data;
411 poll_wait(file, &dev->read_wait, wait);
412 poll_wait(file, &dev->write_wait, wait);
414 if (dev->ring_head != dev->ring_tail)
415 mask |= POLLIN | POLLRDNORM;
416 if (!dev->interrupt_out_busy)
417 mask |= POLLOUT | POLLWRNORM;
425 static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
429 size_t *actual_buffer;
430 size_t bytes_to_read;
433 dev = file->private_data;
435 /* verify that we actually have some data to read */
439 /* lock this object */
440 if (down_interruptible(&dev->sem)) {
441 retval = -ERESTARTSYS;
445 /* verify that the device wasn't unplugged */
446 if (dev->intf == NULL) {
448 err("No device or device unplugged %d\n", retval);
453 if (dev->ring_head == dev->ring_tail) {
454 if (file->f_flags & O_NONBLOCK) {
458 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done);
463 /* actual_buffer contains actual_length + interrupt_in_buffer */
464 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
465 bytes_to_read = min(count, *actual_buffer);
466 if (bytes_to_read < *actual_buffer)
467 dev_warn(&dev->intf->dev, "Read buffer overflow, %zd bytes dropped\n",
468 *actual_buffer-bytes_to_read);
470 /* copy one interrupt_in_buffer from ring_buffer into userspace */
471 if (copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
475 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
477 retval = bytes_to_read;
480 /* unlock the device */
490 static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
491 size_t count, loff_t *ppos)
494 size_t bytes_to_write;
497 dev = file->private_data;
499 /* verify that we actually have some data to write */
503 /* lock this object */
504 if (down_interruptible(&dev->sem)) {
505 retval = -ERESTARTSYS;
509 /* verify that the device wasn't unplugged */
510 if (dev->intf == NULL) {
512 err("No device or device unplugged %d\n", retval);
516 /* wait until previous transfer is finished */
517 if (dev->interrupt_out_busy) {
518 if (file->f_flags & O_NONBLOCK) {
522 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy);
528 /* write the data into interrupt_out_buffer from userspace */
529 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
530 if (bytes_to_write < count)
531 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
532 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __FUNCTION__, count, bytes_to_write);
534 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
539 if (dev->interrupt_out_endpoint == NULL) {
540 /* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
541 retval = usb_control_msg(interface_to_usbdev(dev->intf),
542 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
544 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
546 dev->interrupt_out_buffer,
548 USB_CTRL_SET_TIMEOUT * HZ);
550 err("Couldn't submit HID_REQ_SET_REPORT %d\n", retval);
554 /* send off the urb */
555 usb_fill_int_urb(dev->interrupt_out_urb,
556 interface_to_usbdev(dev->intf),
557 usb_sndintpipe(interface_to_usbdev(dev->intf),
558 dev->interrupt_out_endpoint->bEndpointAddress),
559 dev->interrupt_out_buffer,
561 ld_usb_interrupt_out_callback,
563 dev->interrupt_out_interval);
565 dev->interrupt_out_busy = 1;
568 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
570 dev->interrupt_out_busy = 0;
571 err("Couldn't submit interrupt_out_urb %d\n", retval);
574 retval = bytes_to_write;
577 /* unlock the device */
584 /* file operations needed when we register this driver */
585 static struct file_operations ld_usb_fops = {
586 .owner = THIS_MODULE,
588 .write = ld_usb_write,
590 .release = ld_usb_release,
595 * usb class driver info in order to get a minor number from the usb core,
596 * and to have the device registered with devfs and the driver core
598 static struct usb_class_driver ld_usb_class = {
600 .fops = &ld_usb_fops,
601 .minor_base = USB_LD_MINOR_BASE,
607 * Called by the usb core when a new device is connected that it thinks
608 * this driver might be interested in.
610 static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
612 struct usb_device *udev = interface_to_usbdev(intf);
613 struct ld_usb *dev = NULL;
614 struct usb_host_interface *iface_desc;
615 struct usb_endpoint_descriptor *endpoint;
618 int retval = -ENOMEM;
620 /* allocate memory for our device state and intialize it */
622 dev = kmalloc(sizeof(*dev), GFP_KERNEL);
624 dev_err(&intf->dev, "Out of memory\n");
627 memset(dev, 0x00, sizeof(*dev));
628 init_MUTEX(&dev->sem);
630 init_waitqueue_head(&dev->read_wait);
631 init_waitqueue_head(&dev->write_wait);
633 /* workaround for early firmware versions on fast computers */
634 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) &&
635 ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_CASSY) ||
636 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_COM3LAB)) &&
637 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
638 buffer = kmalloc(256, GFP_KERNEL);
639 if (buffer == NULL) {
640 dev_err(&intf->dev, "Couldn't allocate string buffer\n");
643 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */
644 usb_string(udev, 255, buffer, 256);
648 iface_desc = intf->cur_altsetting;
650 /* set up the endpoint information */
651 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
652 endpoint = &iface_desc->endpoint[i].desc;
654 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
655 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
656 dev->interrupt_in_endpoint = endpoint;
659 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
660 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
661 dev->interrupt_out_endpoint = endpoint;
664 if (dev->interrupt_in_endpoint == NULL) {
665 dev_err(&intf->dev, "Interrupt in endpoint not found\n");
668 if (dev->interrupt_out_endpoint == NULL)
669 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n");
671 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
672 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL);
673 if (!dev->ring_buffer) {
674 dev_err(&intf->dev, "Couldn't allocate ring_buffer\n");
677 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
678 if (!dev->interrupt_in_buffer) {
679 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
682 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
683 if (!dev->interrupt_in_urb) {
684 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
687 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
688 udev->descriptor.bMaxPacketSize0;
689 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL);
690 if (!dev->interrupt_out_buffer) {
691 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
694 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
695 if (!dev->interrupt_out_urb) {
696 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
699 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval;
700 if (dev->interrupt_out_endpoint)
701 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
703 /* we can register the device now, as it is ready */
704 usb_set_intfdata(intf, dev);
706 retval = usb_register_dev(intf, &ld_usb_class);
708 /* something prevented us from registering this driver */
709 dev_err(&intf->dev, "Not able to get a minor for this device.\n");
710 usb_set_intfdata(intf, NULL);
714 /* let the user know what node this device is now attached to */
715 dev_info(&intf->dev, "LD USB Device #%d now attached to major %d minor %d\n",
716 (intf->minor - USB_LD_MINOR_BASE), USB_MAJOR, intf->minor);
730 * Called by the usb core when the device is removed from the system.
732 static void ld_usb_disconnect(struct usb_interface *intf)
737 down(&disconnect_sem);
739 dev = usb_get_intfdata(intf);
740 usb_set_intfdata(intf, NULL);
746 /* give back our minor */
747 usb_deregister_dev(intf, &ld_usb_class);
749 /* if the device is not opened, then we clean up right now */
750 if (!dev->open_count) {
760 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
761 (minor - USB_LD_MINOR_BASE));
764 /* usb specific object needed to register this driver with the usb subsystem */
765 static struct usb_driver ld_usb_driver = {
766 .owner = THIS_MODULE,
768 .probe = ld_usb_probe,
769 .disconnect = ld_usb_disconnect,
770 .id_table = ld_usb_table,
776 static int __init ld_usb_init(void)
780 /* register this driver with the USB subsystem */
781 retval = usb_register(&ld_usb_driver);
783 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval);
791 static void __exit ld_usb_exit(void)
793 /* deregister this driver with the USB subsystem */
794 usb_deregister(&ld_usb_driver);
797 module_init(ld_usb_init);
798 module_exit(ld_usb_exit);