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/config.h>
31 #include <linux/kernel.h>
32 #include <linux/errno.h>
33 #include <linux/init.h>
34 #include <linux/slab.h>
35 #include <linux/module.h>
36 #include <linux/mutex.h>
38 #include <asm/uaccess.h>
39 #include <linux/input.h>
40 #include <linux/usb.h>
41 #include <linux/poll.h>
43 /* Define these values to match your devices */
44 #define USB_VENDOR_ID_LD 0x0f11 /* USB Vendor ID of LD Didactic GmbH */
45 #define USB_DEVICE_ID_LD_CASSY 0x1000 /* USB Product ID of CASSY-S */
46 #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010 /* USB Product ID of Pocket-CASSY */
47 #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020 /* USB Product ID of Mobile-CASSY */
48 #define USB_DEVICE_ID_LD_JWM 0x1080 /* USB Product ID of Joule and Wattmeter */
49 #define USB_DEVICE_ID_LD_DMMP 0x1081 /* USB Product ID of Digital Multimeter P (reserved) */
50 #define USB_DEVICE_ID_LD_UMIP 0x1090 /* USB Product ID of UMI P */
51 #define USB_DEVICE_ID_LD_XRAY1 0x1100 /* USB Product ID of X-Ray Apparatus */
52 #define USB_DEVICE_ID_LD_XRAY2 0x1101 /* USB Product ID of X-Ray Apparatus */
53 #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200 /* USB Product ID of VideoCom */
54 #define USB_DEVICE_ID_LD_COM3LAB 0x2000 /* USB Product ID of COM3LAB */
55 #define USB_DEVICE_ID_LD_TELEPORT 0x2010 /* USB Product ID of Terminal Adapter */
56 #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020 /* USB Product ID of Network Analyser */
57 #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030 /* USB Product ID of Converter Control Unit */
58 #define USB_DEVICE_ID_LD_MACHINETEST 0x2040 /* USB Product ID of Machine Test System */
60 #define USB_VENDOR_ID_VERNIER 0x08f7
61 #define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
62 #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
63 #define USB_DEVICE_ID_VERNIER_SKIP 0x0003
64 #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
67 #ifdef CONFIG_USB_DYNAMIC_MINORS
68 #define USB_LD_MINOR_BASE 0
70 #define USB_LD_MINOR_BASE 176
73 /* table of devices that work with this driver */
74 static struct usb_device_id ld_usb_table [] = {
75 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
76 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
77 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
78 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
79 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
80 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
81 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
82 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
83 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
84 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
85 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
86 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
87 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
88 { USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
89 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
90 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
91 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
92 { USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
93 { } /* Terminating entry */
95 MODULE_DEVICE_TABLE(usb, ld_usb_table);
96 MODULE_VERSION("V0.13");
97 MODULE_AUTHOR("Michael Hund <mhund@ld-didactic.de>");
98 MODULE_DESCRIPTION("LD USB Driver");
99 MODULE_LICENSE("GPL");
100 MODULE_SUPPORTED_DEVICE("LD USB Devices");
102 #ifdef CONFIG_USB_DEBUG
103 static int debug = 1;
105 static int debug = 0;
108 /* Use our own dbg macro */
109 #define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
111 /* Module parameters */
112 module_param(debug, int, S_IRUGO | S_IWUSR);
113 MODULE_PARM_DESC(debug, "Debug enabled or not");
115 /* All interrupt in transfers are collected in a ring buffer to
116 * avoid racing conditions and get better performance of the driver.
118 static int ring_buffer_size = 128;
119 module_param(ring_buffer_size, int, 0);
120 MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
122 /* The write_buffer can contain more than one interrupt out transfer.
124 static int write_buffer_size = 10;
125 module_param(write_buffer_size, int, 0);
126 MODULE_PARM_DESC(write_buffer_size, "Write buffer size in reports");
128 /* As of kernel version 2.6.4 ehci-hcd uses an
129 * "only one interrupt transfer per frame" shortcut
130 * to simplify the scheduling of periodic transfers.
131 * This conflicts with our standard 1ms intervals for in and out URBs.
132 * We use default intervals of 2ms for in and 2ms for out transfers,
133 * which should be fast enough.
134 * Increase the interval to allow more devices that do interrupt transfers,
135 * or set to 1 to use the standard interval from the endpoint descriptors.
137 static int min_interrupt_in_interval = 2;
138 module_param(min_interrupt_in_interval, int, 0);
139 MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms");
141 static int min_interrupt_out_interval = 2;
142 module_param(min_interrupt_out_interval, int, 0);
143 MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms");
145 /* Structure to hold all of our device specific stuff */
147 struct semaphore sem; /* locks this structure */
148 struct usb_interface* intf; /* save off the usb interface pointer */
150 int open_count; /* number of times this port has been opened */
153 unsigned int ring_head;
154 unsigned int ring_tail;
156 wait_queue_head_t read_wait;
157 wait_queue_head_t write_wait;
159 char* interrupt_in_buffer;
160 struct usb_endpoint_descriptor* interrupt_in_endpoint;
161 struct urb* interrupt_in_urb;
162 int interrupt_in_interval;
163 size_t interrupt_in_endpoint_size;
164 int interrupt_in_running;
165 int interrupt_in_done;
167 char* interrupt_out_buffer;
168 struct usb_endpoint_descriptor* interrupt_out_endpoint;
169 struct urb* interrupt_out_urb;
170 int interrupt_out_interval;
171 size_t interrupt_out_endpoint_size;
172 int interrupt_out_busy;
175 /* prevent races between open() and disconnect() */
176 static DEFINE_MUTEX(disconnect_mutex);
178 static struct usb_driver ld_usb_driver;
181 * ld_usb_abort_transfers
182 * aborts transfers and frees associated data structures
184 static void ld_usb_abort_transfers(struct ld_usb *dev)
186 /* shutdown transfer */
187 if (dev->interrupt_in_running) {
188 dev->interrupt_in_running = 0;
190 usb_kill_urb(dev->interrupt_in_urb);
192 if (dev->interrupt_out_busy)
194 usb_kill_urb(dev->interrupt_out_urb);
200 static void ld_usb_delete(struct ld_usb *dev)
202 ld_usb_abort_transfers(dev);
204 /* free data structures */
205 usb_free_urb(dev->interrupt_in_urb);
206 usb_free_urb(dev->interrupt_out_urb);
207 kfree(dev->ring_buffer);
208 kfree(dev->interrupt_in_buffer);
209 kfree(dev->interrupt_out_buffer);
214 * ld_usb_interrupt_in_callback
216 static void ld_usb_interrupt_in_callback(struct urb *urb, struct pt_regs *regs)
218 struct ld_usb *dev = urb->context;
219 size_t *actual_buffer;
220 unsigned int next_ring_head;
224 if (urb->status == -ENOENT ||
225 urb->status == -ECONNRESET ||
226 urb->status == -ESHUTDOWN) {
229 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n",
230 __FUNCTION__, urb->status);
231 goto resubmit; /* maybe we can recover */
235 if (urb->actual_length > 0) {
236 next_ring_head = (dev->ring_head+1) % ring_buffer_size;
237 if (next_ring_head != dev->ring_tail) {
238 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_head*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
239 /* actual_buffer gets urb->actual_length + interrupt_in_buffer */
240 *actual_buffer = urb->actual_length;
241 memcpy(actual_buffer+1, dev->interrupt_in_buffer, urb->actual_length);
242 dev->ring_head = next_ring_head;
243 dbg_info(&dev->intf->dev, "%s: received %d bytes\n",
244 __FUNCTION__, urb->actual_length);
246 dev_warn(&dev->intf->dev,
247 "Ring buffer overflow, %d bytes dropped\n",
252 /* resubmit if we're still running */
253 if (dev->interrupt_in_running && dev->intf) {
254 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
256 dev_err(&dev->intf->dev,
257 "usb_submit_urb failed (%d)\n", retval);
261 dev->interrupt_in_done = 1;
262 wake_up_interruptible(&dev->read_wait);
266 * ld_usb_interrupt_out_callback
268 static void ld_usb_interrupt_out_callback(struct urb *urb, struct pt_regs *regs)
270 struct ld_usb *dev = urb->context;
272 /* sync/async unlink faults aren't errors */
273 if (urb->status && !(urb->status == -ENOENT ||
274 urb->status == -ECONNRESET ||
275 urb->status == -ESHUTDOWN))
276 dbg_info(&dev->intf->dev,
277 "%s - nonzero write interrupt status received: %d\n",
278 __FUNCTION__, urb->status);
280 dev->interrupt_out_busy = 0;
281 wake_up_interruptible(&dev->write_wait);
287 static int ld_usb_open(struct inode *inode, struct file *file)
292 struct usb_interface *interface;
294 nonseekable_open(inode, file);
295 subminor = iminor(inode);
297 mutex_lock(&disconnect_mutex);
299 interface = usb_find_interface(&ld_usb_driver, subminor);
302 err("%s - error, can't find device for minor %d\n",
303 __FUNCTION__, subminor);
305 goto unlock_disconnect_exit;
308 dev = usb_get_intfdata(interface);
312 goto unlock_disconnect_exit;
315 /* lock this device */
316 if (down_interruptible(&dev->sem)) {
317 retval = -ERESTARTSYS;
318 goto unlock_disconnect_exit;
321 /* allow opening only once */
322 if (dev->open_count) {
328 /* initialize in direction */
331 usb_fill_int_urb(dev->interrupt_in_urb,
332 interface_to_usbdev(interface),
333 usb_rcvintpipe(interface_to_usbdev(interface),
334 dev->interrupt_in_endpoint->bEndpointAddress),
335 dev->interrupt_in_buffer,
336 dev->interrupt_in_endpoint_size,
337 ld_usb_interrupt_in_callback,
339 dev->interrupt_in_interval);
341 dev->interrupt_in_running = 1;
342 dev->interrupt_in_done = 0;
344 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
346 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval);
347 dev->interrupt_in_running = 0;
352 /* save device in the file's private structure */
353 file->private_data = dev;
358 unlock_disconnect_exit:
359 mutex_unlock(&disconnect_mutex);
367 static int ld_usb_release(struct inode *inode, struct file *file)
372 dev = file->private_data;
379 if (down_interruptible(&dev->sem)) {
380 retval = -ERESTARTSYS;
384 if (dev->open_count != 1) {
388 if (dev->intf == NULL) {
389 /* the device was unplugged before the file was released */
391 /* unlock here as ld_usb_delete frees dev */
396 /* wait until write transfer is finished */
397 if (dev->interrupt_out_busy)
398 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ);
399 ld_usb_abort_transfers(dev);
412 static unsigned int ld_usb_poll(struct file *file, poll_table *wait)
415 unsigned int mask = 0;
417 dev = file->private_data;
419 poll_wait(file, &dev->read_wait, wait);
420 poll_wait(file, &dev->write_wait, wait);
422 if (dev->ring_head != dev->ring_tail)
423 mask |= POLLIN | POLLRDNORM;
424 if (!dev->interrupt_out_busy)
425 mask |= POLLOUT | POLLWRNORM;
433 static ssize_t ld_usb_read(struct file *file, char __user *buffer, size_t count,
437 size_t *actual_buffer;
438 size_t bytes_to_read;
441 dev = file->private_data;
443 /* verify that we actually have some data to read */
447 /* lock this object */
448 if (down_interruptible(&dev->sem)) {
449 retval = -ERESTARTSYS;
453 /* verify that the device wasn't unplugged */
454 if (dev->intf == NULL) {
456 err("No device or device unplugged %d\n", retval);
461 if (dev->ring_head == dev->ring_tail) {
462 if (file->f_flags & O_NONBLOCK) {
466 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done);
471 /* actual_buffer contains actual_length + interrupt_in_buffer */
472 actual_buffer = (size_t*)(dev->ring_buffer + dev->ring_tail*(sizeof(size_t)+dev->interrupt_in_endpoint_size));
473 bytes_to_read = min(count, *actual_buffer);
474 if (bytes_to_read < *actual_buffer)
475 dev_warn(&dev->intf->dev, "Read buffer overflow, %zd bytes dropped\n",
476 *actual_buffer-bytes_to_read);
478 /* copy one interrupt_in_buffer from ring_buffer into userspace */
479 if (copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
483 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size;
485 retval = bytes_to_read;
488 /* unlock the device */
498 static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
499 size_t count, loff_t *ppos)
502 size_t bytes_to_write;
505 dev = file->private_data;
507 /* verify that we actually have some data to write */
511 /* lock this object */
512 if (down_interruptible(&dev->sem)) {
513 retval = -ERESTARTSYS;
517 /* verify that the device wasn't unplugged */
518 if (dev->intf == NULL) {
520 err("No device or device unplugged %d\n", retval);
524 /* wait until previous transfer is finished */
525 if (dev->interrupt_out_busy) {
526 if (file->f_flags & O_NONBLOCK) {
530 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy);
536 /* write the data into interrupt_out_buffer from userspace */
537 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size);
538 if (bytes_to_write < count)
539 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
540 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __FUNCTION__, count, bytes_to_write);
542 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
547 if (dev->interrupt_out_endpoint == NULL) {
548 /* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
549 retval = usb_control_msg(interface_to_usbdev(dev->intf),
550 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
552 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
554 dev->interrupt_out_buffer,
556 USB_CTRL_SET_TIMEOUT * HZ);
558 err("Couldn't submit HID_REQ_SET_REPORT %d\n", retval);
562 /* send off the urb */
563 usb_fill_int_urb(dev->interrupt_out_urb,
564 interface_to_usbdev(dev->intf),
565 usb_sndintpipe(interface_to_usbdev(dev->intf),
566 dev->interrupt_out_endpoint->bEndpointAddress),
567 dev->interrupt_out_buffer,
569 ld_usb_interrupt_out_callback,
571 dev->interrupt_out_interval);
573 dev->interrupt_out_busy = 1;
576 retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
578 dev->interrupt_out_busy = 0;
579 err("Couldn't submit interrupt_out_urb %d\n", retval);
582 retval = bytes_to_write;
585 /* unlock the device */
592 /* file operations needed when we register this driver */
593 static struct file_operations ld_usb_fops = {
594 .owner = THIS_MODULE,
596 .write = ld_usb_write,
598 .release = ld_usb_release,
603 * usb class driver info in order to get a minor number from the usb core,
604 * and to have the device registered with the driver core
606 static struct usb_class_driver ld_usb_class = {
608 .fops = &ld_usb_fops,
609 .minor_base = USB_LD_MINOR_BASE,
615 * Called by the usb core when a new device is connected that it thinks
616 * this driver might be interested in.
618 static int ld_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
620 struct usb_device *udev = interface_to_usbdev(intf);
621 struct ld_usb *dev = NULL;
622 struct usb_host_interface *iface_desc;
623 struct usb_endpoint_descriptor *endpoint;
626 int retval = -ENOMEM;
628 /* allocate memory for our device state and intialize it */
630 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
632 dev_err(&intf->dev, "Out of memory\n");
635 init_MUTEX(&dev->sem);
637 init_waitqueue_head(&dev->read_wait);
638 init_waitqueue_head(&dev->write_wait);
640 /* workaround for early firmware versions on fast computers */
641 if ((le16_to_cpu(udev->descriptor.idVendor) == USB_VENDOR_ID_LD) &&
642 ((le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_CASSY) ||
643 (le16_to_cpu(udev->descriptor.idProduct) == USB_DEVICE_ID_LD_COM3LAB)) &&
644 (le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
645 buffer = kmalloc(256, GFP_KERNEL);
646 if (buffer == NULL) {
647 dev_err(&intf->dev, "Couldn't allocate string buffer\n");
650 /* usb_string makes SETUP+STALL to leave always ControlReadLoop */
651 usb_string(udev, 255, buffer, 256);
655 iface_desc = intf->cur_altsetting;
657 /* set up the endpoint information */
658 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
659 endpoint = &iface_desc->endpoint[i].desc;
661 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
662 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
663 dev->interrupt_in_endpoint = endpoint;
666 if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
667 ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT)) {
668 dev->interrupt_out_endpoint = endpoint;
671 if (dev->interrupt_in_endpoint == NULL) {
672 dev_err(&intf->dev, "Interrupt in endpoint not found\n");
675 if (dev->interrupt_out_endpoint == NULL)
676 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n");
678 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
679 dev->ring_buffer = kmalloc(ring_buffer_size*(sizeof(size_t)+dev->interrupt_in_endpoint_size), GFP_KERNEL);
680 if (!dev->ring_buffer) {
681 dev_err(&intf->dev, "Couldn't allocate ring_buffer\n");
684 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
685 if (!dev->interrupt_in_buffer) {
686 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
689 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
690 if (!dev->interrupt_in_urb) {
691 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
694 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
695 udev->descriptor.bMaxPacketSize0;
696 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL);
697 if (!dev->interrupt_out_buffer) {
698 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
701 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
702 if (!dev->interrupt_out_urb) {
703 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
706 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval;
707 if (dev->interrupt_out_endpoint)
708 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval;
710 /* we can register the device now, as it is ready */
711 usb_set_intfdata(intf, dev);
713 retval = usb_register_dev(intf, &ld_usb_class);
715 /* something prevented us from registering this driver */
716 dev_err(&intf->dev, "Not able to get a minor for this device.\n");
717 usb_set_intfdata(intf, NULL);
721 /* let the user know what node this device is now attached to */
722 dev_info(&intf->dev, "LD USB Device #%d now attached to major %d minor %d\n",
723 (intf->minor - USB_LD_MINOR_BASE), USB_MAJOR, intf->minor);
737 * Called by the usb core when the device is removed from the system.
739 static void ld_usb_disconnect(struct usb_interface *intf)
744 mutex_lock(&disconnect_mutex);
746 dev = usb_get_intfdata(intf);
747 usb_set_intfdata(intf, NULL);
753 /* give back our minor */
754 usb_deregister_dev(intf, &ld_usb_class);
756 /* if the device is not opened, then we clean up right now */
757 if (!dev->open_count) {
765 mutex_unlock(&disconnect_mutex);
767 dev_info(&intf->dev, "LD USB Device #%d now disconnected\n",
768 (minor - USB_LD_MINOR_BASE));
771 /* usb specific object needed to register this driver with the usb subsystem */
772 static struct usb_driver ld_usb_driver = {
774 .probe = ld_usb_probe,
775 .disconnect = ld_usb_disconnect,
776 .id_table = ld_usb_table,
782 static int __init ld_usb_init(void)
786 /* register this driver with the USB subsystem */
787 retval = usb_register(&ld_usb_driver);
789 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval);
797 static void __exit ld_usb_exit(void)
799 /* deregister this driver with the USB subsystem */
800 usb_deregister(&ld_usb_driver);
803 module_init(ld_usb_init);
804 module_exit(ld_usb_exit);