35 #include <linux/kernel.h>
36 #include <linux/errno.h>
38 #include <linux/slab.h>
39 #include <linux/module.h>
44 #include <linux/input.h>
46 #include <linux/poll.h>
50 #define VENDOR_ID 0x165b
51 #define PRODUCT_ID 0xfad1
53 #ifdef CONFIG_USB_DYNAMIC_MINORS
54 #define USB_ALPHATRACK_MINOR_BASE 0
57 #define USB_ALPHATRACK_MINOR_BASE 176
75 #define SUPPRESS_EXTRA_ONLINE_EVENTS 0
76 #define BUFFERED_WRITES 0
77 #define SUPPRESS_EXTRA_OFFLINE_EVENTS 0
78 #define COMPRESS_FADER_EVENTS 0
80 #define BUFFERED_READS 1
81 #define RING_BUFFER_SIZE 512
82 #define WRITE_BUFFER_SIZE 34
83 #define ALPHATRACK_USB_TIMEOUT 10
84 #define OUTPUT_CMD_SIZE 8
85 #define INPUT_CMD_SIZE 12
86 #define ALPHATRACK_DEBUG 0
91 #define dbg_info(dev, format, arg...) do \
92 { if (debug) dev_info(dev , format , ## arg); } while (0)
94 #define alphatrack_ocmd_info(dev, cmd, format, arg...)
96 #define alphatrack_icmd_info(dev, cmd, format, arg...)
127 "Minimum interrupt in interval in ms");
132 "Minimum interrupt out interval in ms");
183 static struct usb_driver usb_alphatrack_driver;
207 usb_alphatrack_abort_transfers(dev);
220 static void usb_alphatrack_interrupt_in_callback(
struct urb *
urb)
223 unsigned int next_ring_head;
227 if (urb->status == -
ENOENT ||
232 "%s: nonzero status received: %d\n", __func__,
240 "Urb length was %d bytes!!"
241 "Do something intelligent\n", urb->actual_length);
254 #if SUPPRESS_EXTRA_OFFLINE_EVENTS
267 dbg_info(&dev->
intf->dev,
"%s: head, tail are %x, %x\n",
269 next_ring_head = (dev->
ring_head + 1) % ring_buffer_size;
279 "Ring buffer overflow, %d bytes dropped\n",
291 "usb_submit_urb failed (%d)\n", retval);
302 static void usb_alphatrack_interrupt_out_callback(
struct urb *urb)
307 if (urb->status && !(urb->status == -
ENOENT ||
311 "%s - nonzero write interrupt status received: %d\n",
312 __func__, urb->status);
329 subminor = iminor(inode);
336 pr_err(
"%s - error, can't find device for minor %d\n",
339 goto unlock_disconnect_exit;
342 dev = usb_get_intfdata(interface);
346 goto unlock_disconnect_exit;
352 goto unlock_disconnect_exit;
366 interface_to_usbdev(interface),
367 usb_rcvintpipe(interface_to_usbdev(interface),
372 usb_alphatrack_interrupt_in_callback, dev,
383 "Couldn't submit interrupt_in_urb %d\n", retval);
395 unlock_disconnect_exit:
404 static int usb_alphatrack_release(
struct inode *inode,
struct file *file)
430 usb_alphatrack_delete(dev);
440 usb_alphatrack_abort_transfers(dev);
453 static unsigned int usb_alphatrack_poll(
struct file *file,
poll_table *
wait)
456 unsigned int mask = 0;
474 static ssize_t usb_alphatrack_read(
struct file *file,
char __user *
buffer,
475 size_t count, loff_t *ppos)
497 pr_err(
"%s: No device or device unplugged %d\n",
517 ": copying to userspace");
529 dbg_info(&dev->
intf->dev,
"%s: head, tail are %x, %x\n",
545 static ssize_t usb_alphatrack_write(
struct file *file,
546 const char __user *buffer,
size_t count,
550 size_t bytes_to_write;
568 pr_err(
"%s: No device or device unplugged %d\n",
590 if (bytes_to_write < count)
592 "Write buffer overflow, %zd bytes dropped\n",
593 count - bytes_to_write);
595 dbg_info(&dev->
intf->dev,
"%s: count = %zd, bytes_to_write = %zd\n",
596 __func__, count, bytes_to_write);
604 dev_err(&dev->
intf->dev,
"Endpoint should not be be null!\n");
610 interface_to_usbdev(dev->
intf),
611 usb_sndintpipe(interface_to_usbdev(dev->
intf),
615 usb_alphatrack_interrupt_out_callback, dev,
625 "Couldn't submit interrupt_out_urb %d\n", retval);
629 retval = bytes_to_write;
642 .read = usb_alphatrack_read,
643 .write = usb_alphatrack_write,
644 .open = usb_alphatrack_open,
645 .release = usb_alphatrack_release,
646 .poll = usb_alphatrack_poll,
655 static struct usb_class_driver usb_alphatrack_class = {
656 .name =
"alphatrack%d",
657 .fops = &usb_alphatrack_fops,
670 struct usb_device *
udev = interface_to_usbdev(intf);
672 struct usb_host_interface *iface_desc;
682 dev_err(&intf->dev,
"Out of memory\n");
690 iface_desc = intf->cur_altsetting;
693 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++
i) {
694 endpoint = &iface_desc->endpoint[
i].desc;
696 if (usb_endpoint_is_int_in(endpoint))
699 if (usb_endpoint_is_int_out(endpoint))
703 dev_err(&intf->dev,
"Interrupt in endpoint not found\n");
708 "Interrupt out endpoint not found"
709 "(using control endpoint instead)\n");
715 dev_warn(&intf->dev,
"Interrupt in endpoint size is not 64!\n");
717 if (ring_buffer_size == 0)
729 "Couldn't allocate input ring_buffer of size %d\n",
738 dev_err(&intf->dev,
"Couldn't allocate interrupt_in_buffer\n");
743 dev_err(&intf->dev,
"Couldn't allocate old buffer\n");
748 dev_err(&intf->dev,
"Couldn't allocate interrupt_in_urb\n");
754 interrupt_out_endpoint->
760 "Interrupt out endpoint size is not 64!)\n");
762 if (write_buffer_size == 0)
770 dev_err(&intf->dev,
"Couldn't allocate interrupt_out_buffer\n");
778 dev_err(&intf->dev,
"Couldn't allocate write_buffer\n");
784 dev_err(&intf->dev,
"Couldn't allocate interrupt_out_urb\n");
788 min_interrupt_in_interval >
794 min_interrupt_out_interval >
796 bInterval ? min_interrupt_out_interval : dev->
797 interrupt_out_endpoint->bInterval;
800 usb_set_intfdata(intf, dev);
807 "Not able to get a minor for this device.\n");
808 usb_set_intfdata(intf,
NULL);
814 "Alphatrack Device #%d now attached to major %d minor %d\n",
822 usb_alphatrack_delete(dev);
832 static void usb_alphatrack_disconnect(
struct usb_interface *intf)
839 dev = usb_get_intfdata(intf);
840 usb_set_intfdata(intf,
NULL);
852 usb_alphatrack_delete(dev);
861 dev_info(&intf->dev,
"Alphatrack Surface #%d now disconnected\n",
866 static struct usb_driver usb_alphatrack_driver = {
867 .name =
"alphatrack",
868 .probe = usb_alphatrack_probe,
869 .disconnect = usb_alphatrack_disconnect,
870 .id_table = usb_alphatrack_table,