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
27 * V0.13 (mh) Added support for LD X-Ray and Machine Test System
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>
35 #include <linux/mutex.h>
37 #include <asm/uaccess.h>
38 #include <linux/input.h>
39 #include <linux/usb.h>
40 #include <linux/poll.h>
42 /* Define these values to match your devices */
43 #define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */
44 #define USB_DEVICE_ID_LD_CASSY 0x1000 /* USB Product ID of CASSY-S */
45 #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 /* USB Product ID of Pocket-CASSY */
46 #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 /* USB Product ID of Mobile-CASSY */
47 #define USB_DEVICE_ID_LD_JWM 0x1080 /* USB Product ID of Joule and Wattmeter */
48 #define USB_DEVICE_ID_LD_DMMP 0x1081 /* USB Product ID of Digital Multimeter P (reserved) */
49 #define USB_DEVICE_ID_LD_UMIP 0x1090 /* USB Product ID of UMI P */
50 #define USB_DEVICE_ID_LD_XRAY1 0x1100 /* USB Product ID of X-Ray Apparatus */
51 #define USB_DEVICE_ID_LD_XRAY2 0x1101 /* USB Product ID of X-Ray Apparatus */
52 #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 /* USB Product ID of VideoCom */
53 #define USB_DEVICE_ID_LD_COM3LAB 0x2000 /* USB Product ID of COM3LAB */
54 #define USB_DEVICE_ID_LD_TELEPORT 0x2010 /* USB Product ID of Terminal Adapter */
55 #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 /* USB Product ID of Network Analyser */
56 #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 /* USB Product ID of Converter Control Unit */
57 #define USB_DEVICE_ID_LD_MACHINETEST 0x2040 /* USB Product ID of Machine Test System */
59 #define USB_VENDOR_ID_VERNIER 0x08f7
60 #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
61 #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
62 #define USB_DEVICE_ID_VERNIER_SKIP 0x0003
63 #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
66 #ifdef CONFIG_USB_DYNAMIC_MINORS
67 #define USB_LD_MINOR_BASE 0
69 #define USB_LD_MINOR_BASE 176
72 /* table of devices that work with this driver */
73 static struct usb_device_id ld_usb_table [] = {
74 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
76 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
77 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
78 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
79 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
80 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
81 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
82 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
83 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
84 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
85 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
86 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
87 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
88 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
89 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
90 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
91 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
92 { } /* Terminating entry */
94 MODULE_DEVICE_TABLE(usb, ld_usb_table);
95 MODULE_VERSION("V0.13");
96 MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
97 MODULE_DESCRIPTION("LD USB Driver");
98 MODULE_LICENSE("GPL");
99 MODULE_SUPPORTED_DEVICE("LD USB Devices");
101 #ifdef CONFIG_USB_DEBUG
102 static int debug = 1;
104 static int debug = 0;
107 /* Use our own dbg macro */
108 #define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
110 /* Module parameters */
111 module_param(debug, int, S_IRUGO | S_IWUSR);
112 MODULE_PARM_DESC(debug, "Debug enabled or not");
114 /* All interrupt in transfers are collected in a ring buffer to
115 * avoid racing conditions and get better performance of the driver.
117 static int ring_buffer_size = 128;
118 module_param(ring_buffer_size, int, 0);
119 MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
121 /* The write_buffer can contain more than one interrupt out transfer.
123 static int write_buffer_size = 10;
124 module_param(write_buffer_size, int, 0);
125 MODULE_PARM_DESC(write_buffer_size, "Write buffer size in reports");
127 /* As of kernel version 2.6.4 ehci-hcd uses an
128 * "only one interrupt transfer per frame" shortcut
129 * to simplify the scheduling of periodic transfers.
130 * This conflicts with our standard 1ms intervals for in and out URBs.
131 * We use default intervals of 2ms for in and 2ms for out transfers,
132 * which should be fast enough.
133 * Increase the interval to allow more devices that do interrupt transfers,
134 * or set to 1 to use the standard interval from the endpoint descriptors.
136 static int min_interrupt_in_interval = 2;
137 module_param(min_interrupt_in_interval, int, 0);
138 MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms");
140 static int min_interrupt_out_interval = 2;
141 module_param(min_interrupt_out_interval, int, 0);
142 MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms");
144 /* Structure to hold all of our device specific stuff */
146 struct semaphore sem; /* locks this structure */
147 struct usb_interface* intf; /* save off the usb interface pointer */
149 int open_count; /* number of times this port has been opened */
152 unsigned int ring_head;
153 unsigned int ring_tail;
155 wait_queue_head_t read_wait;
156 wait_queue_head_t write_wait;
158 char* interrupt_in_buffer;
159 struct usb_endpoint_descriptor* interrupt_in_endpoint;
160 struct urb* interrupt_in_urb;
161 int interrupt_in_interval;
162 size_t interrupt_in_endpoint_size;
163 int interrupt_in_running;
164 int interrupt_in_done;
166 char* interrupt_out_buffer;
167 struct usb_endpoint_descriptor* interrupt_out_endpoint;
168 struct urb* interrupt_out_urb;
169 int interrupt_out_interval;
170 size_t interrupt_out_endpoint_size;
171 int interrupt_out_busy;
174 /* prevent races between open() and disconnect() */
175 static DEFINE_MUTEX(disconnect_mutex);
177 static struct usb_driver ld_usb_driver;
180 * ld_usb_abort_transfers
181 * aborts transfers and frees associated data structures
183 static void ld_usb_abort_transfers(struct ld_usb *dev)
185 /* shutdown transfer */
186 if (dev->interrupt_in_running) {
187 dev->interrupt_in_running = 0;
189 usb_kill_urb(dev->interrupt_in_urb);
191 if (dev->interrupt_out_busy)
193 usb_kill_urb(dev->interrupt_out_urb);
199 static void ld_usb_delete(struct ld_usb *dev)
201 ld_usb_abort_transfers(dev);
203 /* free data structures */
204 usb_free_urb(dev->interrupt_in_urb);
205 usb_free_urb(dev->interrupt_out_urb);
206 kfree(dev->ring_buffer);
207 kfree(dev->interrupt_in_buffer);
208 kfree(dev->interrupt_out_buffer);
213 * ld_usb_interrupt_in_callback
215 static void ld_usb_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
217 struct ld_usb *dev = urb->context;
218 size_t *actual_buffer;
219 unsigned int next_ring_head;
223 if (urb->status == -ENOENT ||
224 urb->status == -ECONNRESET ||
225 urb->status == -ESHUTDOWN) {
228 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
229 __FUNCTION__, urb->status);
230 goto resubmit; /* maybe we can recover */
234 if (urb->actual_length > 0) {
235 next_ring_head = (dev->ring_head+1) % ring_buffer_size;
236 if (next_ring_head != dev->ring_tail) {
237 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_head*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
238 /* actual_buffer gets urb->actual_length + interrupt_in_buffer */
239 *actual_buffer = urb->actual_length;
240 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
241 dev->ring_head = next_ring_head;
242 dbg_info(&dev->intf->dev, "%s: received %d bytes\n",
243 __FUNCTION__, urb->actual_length);
245 dev_warn(&dev->intf->dev,
246 "Ring buffer overflow, %d bytes dropped\n",
251 /* resubmit if we're still running */
252 if (dev->interrupt_in_running && dev->intf) {
253 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
255 dev_err(&dev->intf->dev,
256 "usb_submit_urb failed (%d)\n", retval);
260 dev->interrupt_in_done = 1;
261 wake_up_interruptible(&dev->read_wait);
265 * ld_usb_interrupt_out_callback
267 static void ld_usb_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
269 struct ld_usb *dev = urb->context;
271 /* sync/async unlink faults aren't errors */
272 if (urb->status && !(urb->status == -ENOENT ||
273 urb->status == -ECONNRESET ||
274 urb->status == -ESHUTDOWN))
275 dbg_info(&dev->intf->dev,
276 "%s - nonzero write interrupt status received: %d\n",
277 __FUNCTION__, urb->status);
279 dev->interrupt_out_busy = 0;
280 wake_up_interruptible(&dev->write_wait);
286 static int ld_usb_open(struct inode *inode, struct file *file)
291 struct usb_interface *interface;
293 nonseekable_open(inode, file);
294 subminor = iminor(inode);
296 mutex_lock(&disconnect_mutex);
298 interface = usb_find_interface(&ld_usb_driver, subminor);
301 err("%s - error, can't find device for minor %d\n",
302 __FUNCTION__, subminor);
304 goto unlock_disconnect_exit;
307 dev = usb_get_intfdata(interface);
311 goto unlock_disconnect_exit;
314 /* lock this device */
315 if (down_interruptible(&dev->sem)) {
316 retval = -ERESTARTSYS;
317 goto unlock_disconnect_exit;
320 /* allow opening only once */
321 if (dev->open_count) {
327 /* initialize in direction */
330 usb_fill_int_urb(dev->interrupt_in_urb,
331 interface_to_usbdev(interface),
332 usb_rcvintpipe(interface_to_usbdev(interface),
333 dev->interrupt_in_endpoint->bEndpointAddress),
334 dev->interrupt_in_buffer,
335 dev->interrupt_in_endpoint_size,
336 ld_usb_interrupt_in_callback,
338 dev->interrupt_in_interval);
340 dev->interrupt_in_running = 1;
341 dev->interrupt_in_done = 0;
343 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
345 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval);
346 dev->interrupt_in_running = 0;
351 /* save device in the file's private structure */
352 file->private_data = dev;
357 unlock_disconnect_exit:
358 mutex_unlock(&disconnect_mutex);
366 static int ld_usb_release(struct inode *inode, struct file *file)
371 dev = file->private_data;
378 if (down_interruptible(&dev->sem)) {
379 retval = -ERESTARTSYS;
383 if (dev->open_count != 1) {
387 if (dev->intf == NULL) {
388 /* the device was unplugged before the file was released */
390 /* unlock here as ld_usb_delete frees dev */
395 /* wait until write transfer is finished */
396 if (dev->interrupt_out_busy)
397 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
398 ld_usb_abort_transfers(dev);
411 static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
414 unsigned int mask = 0;
416 dev = file->private_data;
418 poll_wait(file, &dev->read_wait, wait);
419 poll_wait(file, &dev->write_wait, wait);
421 if (dev->ring_head != dev->ring_tail)
422 mask |= POLLIN | POLLRDNORM;
423 if (!dev->interrupt_out_busy)
424 mask |= POLLOUT | POLLWRNORM;
432 static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
436 size_t *actual_buffer;
437 size_t bytes_to_read;
440 dev = file->private_data;
442 /* verify that we actually have some data to read */
446 /* lock this object */
447 if (down_interruptible(&dev->sem)) {
448 retval = -ERESTARTSYS;
452 /* verify that the device wasn't unplugged */
453 if (dev->intf == NULL) {
455 err("No device or device unplugged %d\n", retval);
460 if (dev->ring_head == dev->ring_tail) {
461 if (file->f_flags & O_NONBLOCK) {
465 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done);
470 /* actual_buffer contains actual_length + interrupt_in_buffer */
471 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
472 bytes_to_read = min(count, *actual_buffer);
473 if (bytes_to_read < *actual_buffer)
474 dev_warn(&dev->intf->dev, "Read buffer overflow, %zd bytes dropped\n",
475 *actual_buffer-bytes_to_read);
477 /* copy one interrupt_in_buffer from ring_buffer into userspace */
478 if (copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
482 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
484 retval = bytes_to_read;
487 /* unlock the device */
497 static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
498 size_t count, loff_t *ppos)
501 size_t bytes_to_write;
504 dev = file->private_data;
506 /* verify that we actually have some data to write */
510 /* lock this object */
511 if (down_interruptible(&dev->sem)) {
512 retval = -ERESTARTSYS;
516 /* verify that the device wasn't unplugged */
517 if (dev->intf == NULL) {
519 err("No device or device unplugged %d\n", retval);
523 /* wait until previous transfer is finished */
524 if (dev->interrupt_out_busy) {
525 if (file->f_flags & O_NONBLOCK) {
529 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy);
535 /* write the data into interrupt_out_buffer from userspace */
536 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
537 if (bytes_to_write < count)
538 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
539 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __FUNCTION__, count, bytes_to_write);
541 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
546 if (dev->interrupt_out_endpoint == NULL) {
547 /* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
548 retval = usb_control_msg(interface_to_usbdev(dev->intf),
549 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
551 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
553 dev->interrupt_out_buffer,
555 USB_CTRL_SET_TIMEOUT * HZ);
557 err("Couldn't submit HID_REQ_SET_REPORT %d\n", retval);
561 /* send off the urb */
562 usb_fill_int_urb(dev->interrupt_out_urb,
563 interface_to_usbdev(dev->intf),
564 usb_sndintpipe(interface_to_usbdev(dev->intf),
565 dev->interrupt_out_endpoint->bEndpointAddress),
566 dev->interrupt_out_buffer,
568 ld_usb_interrupt_out_callback,
570 dev->interrupt_out_interval);
572 dev->interrupt_out_busy = 1;
575 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
577 dev->interrupt_out_busy = 0;
578 err("Couldn't submit interrupt_out_urb %d\n", retval);
581 retval = bytes_to_write;
584 /* unlock the device */
591 /* file operations needed when we register this driver */
592 static const struct file_operations ld_usb_fops = {
593 .owner = THIS_MODULE,
595 .write = ld_usb_write,
597 .release = ld_usb_release,
602 * usb class driver info in order to get a minor number from the usb core,
603 * and to have the device registered with the driver core
605 static struct usb_class_driver ld_usb_class = {
607 .fops = &ld_usb_fops,
608 .minor_base = USB_LD_MINOR_BASE,
614 * Called by the usb core when a new device is connected that it thinks
615 * this driver might be interested in.
617 static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
619 struct usb_device *udev = interface_to_usbdev(intf);
620 struct ld_usb *dev = NULL;
621 struct usb_host_interface *iface_desc;
622 struct usb_endpoint_descriptor *endpoint;
625 int retval = -ENOMEM;
627 /* allocate memory for our device state and intialize it */
629 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
631 dev_err(&intf->dev, "Out of memory\n");
634 init_MUTEX(&dev->sem);
636 init_waitqueue_head(&dev->read_wait);
637 init_waitqueue_head(&dev->write_wait);
639 /* workaround for early firmware versions on fast computers */
640 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) &&
641 ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_CASSY) ||
642 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_COM3LAB)) &&
643 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
644 buffer = kmalloc(256, GFP_KERNEL);
645 if (buffer == NULL) {
646 dev_err(&intf->dev, "Couldn't allocate string buffer\n");
649 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */
650 usb_string(udev, 255, buffer, 256);
654 iface_desc = intf->cur_altsetting;
656 /* set up the endpoint information */
657 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
658 endpoint = &iface_desc->endpoint[i].desc;
660 if (usb_endpoint_is_int_in(endpoint))
661 dev->interrupt_in_endpoint = endpoint;
663 if (usb_endpoint_is_int_out(endpoint))
664 dev->interrupt_out_endpoint = endpoint;
666 if (dev->interrupt_in_endpoint == NULL) {
667 dev_err(&intf->dev, "Interrupt in endpoint not found\n");
670 if (dev->interrupt_out_endpoint == NULL)
671 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n");
673 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
674 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL);
675 if (!dev->ring_buffer) {
676 dev_err(&intf->dev, "Couldn't allocate ring_buffer\n");
679 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
680 if (!dev->interrupt_in_buffer) {
681 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
684 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
685 if (!dev->interrupt_in_urb) {
686 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
689 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
690 udev->descriptor.bMaxPacketSize0;
691 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL);
692 if (!dev->interrupt_out_buffer) {
693 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
696 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
697 if (!dev->interrupt_out_urb) {
698 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
701 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval;
702 if (dev->interrupt_out_endpoint)
703 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
705 /* we can register the device now, as it is ready */
706 usb_set_intfdata(intf, dev);
708 retval = usb_register_dev(intf, &ld_usb_class);
710 /* something prevented us from registering this driver */
711 dev_err(&intf->dev, "Not able to get a minor for this device.\n");
712 usb_set_intfdata(intf, NULL);
716 /* let the user know what node this device is now attached to */
717 dev_info(&intf->dev, "LD USB Device #%d now attached to major %d minor %d\n",
718 (intf->minor - USB_LD_MINOR_BASE), USB_MAJOR, intf->minor);
732 * Called by the usb core when the device is removed from the system.
734 static void ld_usb_disconnect(struct usb_interface *intf)
739 mutex_lock(&disconnect_mutex);
741 dev = usb_get_intfdata(intf);
742 usb_set_intfdata(intf, NULL);
748 /* give back our minor */
749 usb_deregister_dev(intf, &ld_usb_class);
751 /* if the device is not opened, then we clean up right now */
752 if (!dev->open_count) {
760 mutex_unlock(&disconnect_mutex);
762 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
763 (minor - USB_LD_MINOR_BASE));
766 /* usb specific object needed to register this driver with the usb subsystem */
767 static struct usb_driver ld_usb_driver = {
769 .probe = ld_usb_probe,
770 .disconnect = ld_usb_disconnect,
771 .id_table = ld_usb_table,
777 static int __init ld_usb_init(void)
781 /* register this driver with the USB subsystem */
782 retval = usb_register(&ld_usb_driver);
784 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval);
792 static void __exit ld_usb_exit(void)
794 /* deregister this driver with the USB subsystem */
795 usb_deregister(&ld_usb_driver);
798 module_init(ld_usb_init);
799 module_exit(ld_usb_exit);