25 #include <linux/kernel.h>
26 #include <linux/errno.h>
28 #include <linux/slab.h>
29 #include <linux/module.h>
32 #include <asm/uaccess.h>
33 #include <linux/input.h>
35 #include <linux/poll.h>
38 #define USB_VENDOR_ID_LD 0x0f11
39 #define USB_DEVICE_ID_LD_CASSY 0x1000
40 #define USB_DEVICE_ID_LD_CASSY2 0x1001
41 #define USB_DEVICE_ID_LD_POCKETCASSY 0x1010
42 #define USB_DEVICE_ID_LD_POCKETCASSY2 0x1011
43 #define USB_DEVICE_ID_LD_MOBILECASSY 0x1020
44 #define USB_DEVICE_ID_LD_MOBILECASSY2 0x1021
45 #define USB_DEVICE_ID_LD_MICROCASSYVOLTAGE 0x1031
46 #define USB_DEVICE_ID_LD_MICROCASSYCURRENT 0x1032
47 #define USB_DEVICE_ID_LD_MICROCASSYTIME 0x1033
48 #define USB_DEVICE_ID_LD_MICROCASSYTEMPERATURE 0x1035
49 #define USB_DEVICE_ID_LD_MICROCASSYPH 0x1038
50 #define USB_DEVICE_ID_LD_JWM 0x1080
51 #define USB_DEVICE_ID_LD_DMMP 0x1081
52 #define USB_DEVICE_ID_LD_UMIP 0x1090
53 #define USB_DEVICE_ID_LD_UMIC 0x10A0
54 #define USB_DEVICE_ID_LD_UMIB 0x10B0
55 #define USB_DEVICE_ID_LD_XRAY 0x1100
56 #define USB_DEVICE_ID_LD_XRAY2 0x1101
57 #define USB_DEVICE_ID_LD_XRAYCT 0x1110
58 #define USB_DEVICE_ID_LD_VIDEOCOM 0x1200
59 #define USB_DEVICE_ID_LD_MOTOR 0x1210
60 #define USB_DEVICE_ID_LD_COM3LAB 0x2000
61 #define USB_DEVICE_ID_LD_TELEPORT 0x2010
62 #define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020
63 #define USB_DEVICE_ID_LD_POWERCONTROL 0x2030
64 #define USB_DEVICE_ID_LD_MACHINETEST 0x2040
65 #define USB_DEVICE_ID_LD_MOSTANALYSER 0x2050
66 #define USB_DEVICE_ID_LD_MOSTANALYSER2 0x2051
67 #define USB_DEVICE_ID_LD_ABSESP 0x2060
68 #define USB_DEVICE_ID_LD_AUTODATABUS 0x2070
69 #define USB_DEVICE_ID_LD_MCT 0x2080
70 #define USB_DEVICE_ID_LD_HYBRID 0x2090
71 #define USB_DEVICE_ID_LD_HEATCONTROL 0x20A0
73 #define USB_VENDOR_ID_VERNIER 0x08f7
74 #define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
75 #define USB_DEVICE_ID_VERNIER_SKIP 0x0003
76 #define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
77 #define USB_DEVICE_ID_VERNIER_LCSPEC 0x0006
79 #ifdef CONFIG_USB_DYNAMIC_MINORS
80 #define USB_LD_MINOR_BASE 0
82 #define USB_LD_MINOR_BASE 176
132 #ifdef CONFIG_USB_DEBUG
133 static int debug = 1;
135 static int debug = 0;
139 #define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0)
148 static int ring_buffer_size = 128;
154 static int write_buffer_size = 10;
167 static int min_interrupt_in_interval = 2;
169 MODULE_PARM_DESC(min_interrupt_in_interval,
"Minimum interrupt in interval in ms");
171 static int min_interrupt_out_interval = 2;
173 MODULE_PARM_DESC(min_interrupt_out_interval,
"Minimum interrupt out interval in ms");
207 static struct usb_driver ld_usb_driver;
213 static void ld_usb_abort_transfers(
struct ld_usb *
dev)
229 static void ld_usb_delete(
struct ld_usb *dev)
231 ld_usb_abort_transfers(dev);
245 static void ld_usb_interrupt_in_callback(
struct urb *
urb)
247 struct ld_usb *dev = urb->context;
248 size_t *actual_buffer;
249 unsigned int next_ring_head;
259 dbg_info(&dev->
intf->dev,
"%s: nonzero status received: %d\n",
261 spin_lock(&dev->
rbsl);
266 spin_lock(&dev->
rbsl);
267 if (urb->actual_length > 0) {
268 next_ring_head = (dev->
ring_head+1) % ring_buffer_size;
272 *actual_buffer = urb->actual_length;
276 __func__, urb->actual_length);
279 "Ring buffer overflow, %d bytes dropped\n",
291 "usb_submit_urb failed (%d)\n", retval);
295 spin_unlock(&dev->
rbsl);
304 static void ld_usb_interrupt_out_callback(
struct urb *urb)
306 struct ld_usb *dev = urb->context;
307 int status = urb->status;
310 if (status && !(status == -
ENOENT ||
314 "%s - nonzero write interrupt status received: %d\n",
332 subminor = iminor(inode);
342 dev = usb_get_intfdata(interface);
363 interface_to_usbdev(interface),
364 usb_rcvintpipe(interface_to_usbdev(interface),
368 ld_usb_interrupt_in_callback,
377 dev_err(&interface->dev,
"Couldn't submit interrupt_in_urb %d\n", retval);
395 static int ld_usb_release(
struct inode *inode,
struct file *file)
427 ld_usb_abort_transfers(dev);
440 static unsigned int ld_usb_poll(
struct file *file,
poll_table *
wait)
443 unsigned int mask = 0;
468 size_t *actual_buffer;
469 size_t bytes_to_read;
488 printk(
KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
493 spin_lock_irq(&dev->
rbsl);
496 spin_unlock_irq(&dev->
rbsl);
505 spin_unlock_irq(&dev->
rbsl);
510 bytes_to_read =
min(count, *actual_buffer);
511 if (bytes_to_read < *actual_buffer)
512 dev_warn(&dev->
intf->dev,
"Read buffer overflow, %zd bytes dropped\n",
513 *actual_buffer-bytes_to_read);
516 if (
copy_to_user(buffer, actual_buffer+1, bytes_to_read)) {
522 retval = bytes_to_read;
524 spin_lock_irq(&dev->
rbsl);
527 spin_unlock_irq(&dev->
rbsl);
532 spin_unlock_irq(&dev->
rbsl);
546 static ssize_t ld_usb_write(
struct file *file,
const char __user *buffer,
547 size_t count, loff_t *ppos)
550 size_t bytes_to_write;
568 printk(
KERN_ERR "ldusb: No device or device unplugged %d\n", retval);
586 if (bytes_to_write < count)
587 dev_warn(&dev->
intf->dev,
"Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write);
588 dbg_info(&dev->
intf->dev,
"%s: count = %zd, bytes_to_write = %zd\n", __func__, count, bytes_to_write);
598 usb_sndctrlpipe(interface_to_usbdev(dev->
intf), 0),
604 USB_CTRL_SET_TIMEOUT *
HZ);
607 "Couldn't submit HID_REQ_SET_REPORT %d\n",
614 interface_to_usbdev(dev->
intf),
615 usb_sndintpipe(interface_to_usbdev(dev->
intf),
619 ld_usb_interrupt_out_callback,
630 "Couldn't submit interrupt_out_urb %d\n", retval);
633 retval = bytes_to_write;
647 .write = ld_usb_write,
649 .release = ld_usb_release,
658 static struct usb_class_driver ld_usb_class = {
660 .fops = &ld_usb_fops,
672 struct usb_device *
udev = interface_to_usbdev(intf);
674 struct usb_host_interface *iface_desc;
684 dev_err(&intf->dev,
"Out of memory\n");
697 (
le16_to_cpu(udev->descriptor.bcdDevice) <= 0x103)) {
699 if (buffer ==
NULL) {
700 dev_err(&intf->dev,
"Couldn't allocate string buffer\n");
708 iface_desc = intf->cur_altsetting;
711 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++
i) {
712 endpoint = &iface_desc->endpoint[
i].desc;
714 if (usb_endpoint_is_int_in(endpoint))
717 if (usb_endpoint_is_int_out(endpoint))
721 dev_err(&intf->dev,
"Interrupt in endpoint not found\n");
725 dev_warn(&intf->dev,
"Interrupt out endpoint not found (using control endpoint instead)\n");
730 dev_err(&intf->dev,
"Couldn't allocate ring_buffer\n");
735 dev_err(&intf->dev,
"Couldn't allocate interrupt_in_buffer\n");
740 dev_err(&intf->dev,
"Couldn't allocate interrupt_in_urb\n");
747 dev_err(&intf->dev,
"Couldn't allocate interrupt_out_buffer\n");
752 dev_err(&intf->dev,
"Couldn't allocate interrupt_out_urb\n");
760 usb_set_intfdata(intf, dev);
765 dev_err(&intf->dev,
"Not able to get a minor for this device.\n");
766 usb_set_intfdata(intf,
NULL);
771 dev_info(&intf->dev,
"LD USB Device #%d now attached to major %d minor %d\n",
793 dev = usb_get_intfdata(intf);
794 usb_set_intfdata(intf,
NULL);
815 dev_info(&intf->dev,
"LD USB Device #%d now disconnected\n",
820 static struct usb_driver ld_usb_driver = {
822 .probe = ld_usb_probe,
823 .disconnect = ld_usb_disconnect,
824 .id_table = ld_usb_table,