2
* Frontier Designs Tranzport driver
4
* Copyright (C) 2007 Michael Taht (m@taht.net)
6
* Based on the usbled driver and ldusb drivers by
8
* Copyright (C) 2004 Greg Kroah-Hartman (greg@kroah.com)
9
* Copyright (C) 2005 Michael Hund <mhund@ld-didactic.de>
11
* The ldusb driver was, in turn, derived from Lego USB Tower driver
12
* Copyright (C) 2003 David Glance <advidgsf@sourceforge.net>
13
* 2001-2004 Juergen Stuber <starblue@users.sourceforge.net>
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, version 2.
22
* This driver uses a ring buffer for time critical reading of
23
* interrupt in reports and provides read and write methods for
24
* raw interrupt reports.
27
/* Note: this currently uses a dumb ringbuffer for reads and writes.
28
* A more optimal driver would cache and kill off outstanding urbs that are
29
* now invalid, and ignore ones that already were in the queue but valid
30
* as we only have 17 commands for the tranzport. In particular this is
31
* key for getting lights to flash in time as otherwise many commands
32
* can be buffered up before the light change makes it to the interface.
35
#include <linux/kernel.h>
36
#include <linux/errno.h>
37
#include <linux/init.h>
38
#include <linux/slab.h>
39
#include <linux/module.h>
40
#include <linux/mutex.h>
42
#include <linux/uaccess.h>
43
#include <linux/input.h>
44
#include <linux/usb.h>
45
#include <linux/poll.h>
47
/* Define these values to match your devices */
48
#define VENDOR_ID 0x165b
49
#define PRODUCT_ID 0x8101
51
#ifdef CONFIG_USB_DYNAMIC_MINORS
52
#define USB_TRANZPORT_MINOR_BASE 0
53
#else /* FIXME 177- is the another driver's minor - apply for a minor soon */
54
#define USB_TRANZPORT_MINOR_BASE 177
57
/* table of devices that work with this driver */
58
static struct usb_device_id usb_tranzport_table[] = {
59
{USB_DEVICE(VENDOR_ID, PRODUCT_ID)},
60
{} /* Terminating entry */
63
MODULE_DEVICE_TABLE(usb, usb_tranzport_table);
64
MODULE_VERSION("0.35");
65
MODULE_AUTHOR("Mike Taht <m@taht.net>");
66
MODULE_DESCRIPTION("Tranzport USB Driver");
67
MODULE_LICENSE("GPL");
68
MODULE_SUPPORTED_DEVICE("Frontier Designs Tranzport Control Surface");
70
#define SUPPRESS_EXTRA_OFFLINE_EVENTS 1
71
#define COMPRESS_WHEEL_EVENTS 1
72
#define BUFFERED_READS 1
73
#define RING_BUFFER_SIZE 1000
74
#define WRITE_BUFFER_SIZE 34
75
#define TRANZPORT_USB_TIMEOUT 10
76
#define TRANZPORT_DEBUG 0
78
static int debug = TRANZPORT_DEBUG;
80
/* Use our own dbg macro */
81
#define dbg_info(dev, format, arg...) do \
82
{ if (debug) dev_info(dev , format , ## arg); } while (0)
84
/* Module parameters */
86
module_param(debug, int, S_IRUGO | S_IWUSR);
87
MODULE_PARM_DESC(debug, "Debug enabled or not");
89
/* All interrupt in transfers are collected in a ring buffer to
90
* avoid racing conditions and get better performance of the driver.
93
static int ring_buffer_size = RING_BUFFER_SIZE;
95
module_param(ring_buffer_size, int, S_IRUGO);
96
MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
98
/* The write_buffer can one day contain more than one interrupt out transfer.
100
static int write_buffer_size = WRITE_BUFFER_SIZE;
101
module_param(write_buffer_size, int, S_IRUGO);
102
MODULE_PARM_DESC(write_buffer_size, "Write buffer size");
105
* Increase the interval for debugging purposes.
106
* or set to 1 to use the standard interval from the endpoint descriptors.
109
static int min_interrupt_in_interval = TRANZPORT_USB_TIMEOUT;
110
module_param(min_interrupt_in_interval, int, 0);
111
MODULE_PARM_DESC(min_interrupt_in_interval,
112
"Minimum interrupt in interval in ms");
114
static int min_interrupt_out_interval = TRANZPORT_USB_TIMEOUT;
115
module_param(min_interrupt_out_interval, int, 0);
116
MODULE_PARM_DESC(min_interrupt_out_interval,
117
"Minimum interrupt out interval in ms");
119
struct tranzport_cmd {
120
unsigned char cmd[8];
123
/* Structure to hold all of our device specific stuff */
125
struct usb_tranzport {
126
struct semaphore sem; /* locks this structure */
127
struct usb_interface *intf; /* save off the usb interface pointer */
128
int open_count; /* number of times this port opened */
129
struct tranzport_cmd (*ring_buffer)[RING_BUFFER_SIZE];
130
unsigned int ring_head;
131
unsigned int ring_tail;
132
wait_queue_head_t read_wait;
133
wait_queue_head_t write_wait;
134
unsigned char *interrupt_in_buffer;
135
struct usb_endpoint_descriptor *interrupt_in_endpoint;
136
struct urb *interrupt_in_urb;
137
int interrupt_in_interval;
138
size_t interrupt_in_endpoint_size;
139
int interrupt_in_running;
140
int interrupt_in_done;
141
char *interrupt_out_buffer;
142
struct usb_endpoint_descriptor *interrupt_out_endpoint;
143
struct urb *interrupt_out_urb;
144
int interrupt_out_interval;
145
size_t interrupt_out_endpoint_size;
146
int interrupt_out_busy;
150
unsigned char enable; /* 0 if disabled 1 if enabled */
151
unsigned char offline; /* if the device is out of range or asleep */
152
unsigned char compress_wheel; /* flag to compress wheel events */
155
/* prevent races between open() and disconnect() */
156
static DEFINE_MUTEX(disconnect_mutex);
158
static struct usb_driver usb_tranzport_driver;
161
* usb_tranzport_abort_transfers
162
* aborts transfers and frees associated data structures
164
static void usb_tranzport_abort_transfers(struct usb_tranzport *dev)
166
/* shutdown transfer */
167
if (dev->interrupt_in_running) {
168
dev->interrupt_in_running = 0;
170
usb_kill_urb(dev->interrupt_in_urb);
172
if (dev->interrupt_out_busy)
174
usb_kill_urb(dev->interrupt_out_urb);
177
#define show_int(value) \
178
static ssize_t show_##value(struct device *dev, \
179
struct device_attribute *attr, char *buf) \
181
struct usb_interface *intf = to_usb_interface(dev); \
182
struct usb_tranzport *t = usb_get_intfdata(intf); \
183
return sprintf(buf, "%d\n", t->value); \
185
static DEVICE_ATTR(value, S_IRUGO, show_##value, NULL);
187
#define show_set_int(value) \
188
static ssize_t show_##value(struct device *dev, \
189
struct device_attribute *attr, char *buf) \
191
struct usb_interface *intf = to_usb_interface(dev); \
192
struct usb_tranzport *t = usb_get_intfdata(intf); \
193
return sprintf(buf, "%d\n", t->value); \
195
static ssize_t set_##value(struct device *dev, \
196
struct device_attribute *attr, \
197
const char *buf, size_t count) \
199
struct usb_interface *intf = to_usb_interface(dev); \
200
struct usb_tranzport *t = usb_get_intfdata(intf); \
201
int temp = simple_strtoul(buf, NULL, 10); \
205
static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
209
show_set_int(compress_wheel);
212
* usb_tranzport_delete
214
static void usb_tranzport_delete(struct usb_tranzport *dev)
216
usb_tranzport_abort_transfers(dev);
217
if (dev->intf != NULL) {
218
device_remove_file(&dev->intf->dev, &dev_attr_enable);
219
device_remove_file(&dev->intf->dev, &dev_attr_offline);
220
device_remove_file(&dev->intf->dev, &dev_attr_compress_wheel);
223
/* free data structures */
224
usb_free_urb(dev->interrupt_in_urb);
225
usb_free_urb(dev->interrupt_out_urb);
226
kfree(dev->ring_buffer);
227
kfree(dev->interrupt_in_buffer);
228
kfree(dev->interrupt_out_buffer);
233
* usb_tranzport_interrupt_in_callback
236
static void usb_tranzport_interrupt_in_callback(struct urb *urb)
238
struct usb_tranzport *dev = urb->context;
239
unsigned int next_ring_head;
243
if (urb->status == -ENOENT ||
244
urb->status == -ECONNRESET ||
245
urb->status == -ESHUTDOWN) {
248
dbg_info(&dev->intf->dev,
249
"%s: nonzero status received: %d\n",
250
__func__, urb->status);
251
goto resubmit; /* maybe we can recover */
255
if (urb->actual_length != 8) {
256
dev_warn(&dev->intf->dev,
257
"Urb length was %d bytes!!"
258
"Do something intelligent \n",
261
dbg_info(&dev->intf->dev,
262
"%s: received: %02x%02x%02x%02x%02x%02x%02x%02x\n",
263
__func__, dev->interrupt_in_buffer[0],
264
dev->interrupt_in_buffer[1],
265
dev->interrupt_in_buffer[2],
266
dev->interrupt_in_buffer[3],
267
dev->interrupt_in_buffer[4],
268
dev->interrupt_in_buffer[5],
269
dev->interrupt_in_buffer[6],
270
dev->interrupt_in_buffer[7]);
271
#if SUPPRESS_EXTRA_OFFLINE_EVENTS
272
if (dev->offline == 2 && dev->interrupt_in_buffer[1] == 0xff)
274
if (dev->offline == 1 && dev->interrupt_in_buffer[1] == 0xff) {
279
/* Always pass one offline event up the stack */
280
if (dev->offline > 0 && dev->interrupt_in_buffer[1] != 0xff)
282
if (dev->offline == 0 && dev->interrupt_in_buffer[1] == 0xff)
285
#endif /* SUPPRESS_EXTRA_OFFLINE_EVENTS */
286
dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n",
287
__func__, dev->ring_head, dev->ring_tail);
289
next_ring_head = (dev->ring_head + 1) % ring_buffer_size;
291
if (next_ring_head != dev->ring_tail) {
292
memcpy(&((*dev->ring_buffer)[dev->ring_head]),
293
dev->interrupt_in_buffer, urb->actual_length);
294
dev->ring_head = next_ring_head;
296
memset(dev->interrupt_in_buffer, 0, urb->actual_length);
298
dev_warn(&dev->intf->dev,
299
"Ring buffer overflow, %d bytes dropped\n",
301
memset(dev->interrupt_in_buffer, 0, urb->actual_length);
306
/* resubmit if we're still running */
307
if (dev->interrupt_in_running && dev->intf) {
308
retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
310
dev_err(&dev->intf->dev,
311
"usb_submit_urb failed (%d)\n", retval);
315
dev->interrupt_in_done = 1;
316
wake_up_interruptible(&dev->read_wait);
320
* usb_tranzport_interrupt_out_callback
322
static void usb_tranzport_interrupt_out_callback(struct urb *urb)
324
struct usb_tranzport *dev = urb->context;
325
/* sync/async unlink faults aren't errors */
326
if (urb->status && !(urb->status == -ENOENT ||
327
urb->status == -ECONNRESET ||
328
urb->status == -ESHUTDOWN))
329
dbg_info(&dev->intf->dev,
330
"%s - nonzero write interrupt status received: %d\n",
331
__func__, urb->status);
333
dev->interrupt_out_busy = 0;
334
wake_up_interruptible(&dev->write_wait);
339
static int usb_tranzport_open(struct inode *inode, struct file *file)
341
struct usb_tranzport *dev;
344
struct usb_interface *interface;
346
nonseekable_open(inode, file);
347
subminor = iminor(inode);
349
mutex_lock(&disconnect_mutex);
351
interface = usb_find_interface(&usb_tranzport_driver, subminor);
354
err("%s - error, can't find device for minor %d\n",
357
goto unlock_disconnect_exit;
360
dev = usb_get_intfdata(interface);
364
goto unlock_disconnect_exit;
367
/* lock this device */
368
if (down_interruptible(&dev->sem)) {
369
retval = -ERESTARTSYS;
370
goto unlock_disconnect_exit;
373
/* allow opening only once */
374
if (dev->open_count) {
380
/* initialize in direction */
383
usb_fill_int_urb(dev->interrupt_in_urb,
384
interface_to_usbdev(interface),
385
usb_rcvintpipe(interface_to_usbdev(interface),
386
dev->interrupt_in_endpoint->
388
dev->interrupt_in_buffer,
389
dev->interrupt_in_endpoint_size,
390
usb_tranzport_interrupt_in_callback, dev,
391
dev->interrupt_in_interval);
393
dev->interrupt_in_running = 1;
394
dev->interrupt_in_done = 0;
397
dev->compress_wheel = 1;
399
retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
401
dev_err(&interface->dev,
402
"Couldn't submit interrupt_in_urb %d\n", retval);
403
dev->interrupt_in_running = 0;
408
/* save device in the file's private structure */
409
file->private_data = dev;
414
unlock_disconnect_exit:
415
mutex_unlock(&disconnect_mutex);
421
* usb_tranzport_release
423
static int usb_tranzport_release(struct inode *inode, struct file *file)
425
struct usb_tranzport *dev;
428
dev = file->private_data;
435
if (down_interruptible(&dev->sem)) {
436
retval = -ERESTARTSYS;
440
if (dev->open_count != 1) {
445
if (dev->intf == NULL) {
446
/* the device was unplugged before the file was released */
448
/* unlock here as usb_tranzport_delete frees dev */
449
usb_tranzport_delete(dev);
454
/* wait until write transfer is finished */
455
if (dev->interrupt_out_busy)
456
wait_event_interruptible_timeout(dev->write_wait,
457
!dev->interrupt_out_busy,
459
usb_tranzport_abort_transfers(dev);
472
static unsigned int usb_tranzport_poll(struct file *file, poll_table * wait)
474
struct usb_tranzport *dev;
475
unsigned int mask = 0;
476
dev = file->private_data;
477
poll_wait(file, &dev->read_wait, wait);
478
poll_wait(file, &dev->write_wait, wait);
479
if (dev->ring_head != dev->ring_tail)
480
mask |= POLLIN | POLLRDNORM;
481
if (!dev->interrupt_out_busy)
482
mask |= POLLOUT | POLLWRNORM;
489
static ssize_t usb_tranzport_read(struct file *file, char __user *buffer,
490
size_t count, loff_t *ppos)
492
struct usb_tranzport *dev;
497
#if COMPRESS_WHEEL_EVENTS
498
signed char oldwheel;
499
signed char newwheel;
504
/* do I have such a thing as a null event? */
506
dev = file->private_data;
508
/* verify that we actually have some data to read */
512
/* lock this object */
513
if (down_interruptible(&dev->sem)) {
514
retval = -ERESTARTSYS;
518
/* verify that the device wasn't unplugged */ if (dev->intf == NULL) {
520
err("No device or device unplugged %d\n", retval);
524
while (dev->ring_head == dev->ring_tail) {
526
if (file->f_flags & O_NONBLOCK) {
530
/* tiny race - FIXME: make atomic? */
531
/* atomic_cmp_exchange(&dev->interrupt_in_done,0,0); */
532
dev->interrupt_in_done = 0;
533
retval = wait_event_interruptible(dev->read_wait,
534
dev->interrupt_in_done);
539
dbg_info(&dev->intf->dev,
540
"%s: copying to userspace: "
541
"%02x%02x%02x%02x%02x%02x%02x%02x\n",
543
(*dev->ring_buffer)[dev->ring_tail].cmd[0],
544
(*dev->ring_buffer)[dev->ring_tail].cmd[1],
545
(*dev->ring_buffer)[dev->ring_tail].cmd[2],
546
(*dev->ring_buffer)[dev->ring_tail].cmd[3],
547
(*dev->ring_buffer)[dev->ring_tail].cmd[4],
548
(*dev->ring_buffer)[dev->ring_tail].cmd[5],
549
(*dev->ring_buffer)[dev->ring_tail].cmd[6],
550
(*dev->ring_buffer)[dev->ring_tail].cmd[7]);
554
while ((c < count) && (dev->ring_tail != dev->ring_head)) {
556
#if COMPRESS_WHEEL_EVENTS
557
next_tail = (dev->ring_tail+1) % ring_buffer_size;
558
if (dev->compress_wheel)
560
while (dev->ring_head != next_tail && cancompress == 1) {
561
newwheel = (*dev->ring_buffer)[next_tail].cmd[6];
562
oldwheel = (*dev->ring_buffer)[dev->ring_tail].cmd[6];
563
/* if both are wheel events, and
564
no buttons have changes (FIXME, do I have to check?),
565
and we are the same sign, we can compress +- 7F
567
dbg_info(&dev->intf->dev,
568
"%s: trying to compress: "
569
"%02x%02x%02x%02x%02x%02x%02x%02x\n",
571
(*dev->ring_buffer)[dev->ring_tail].cmd[0],
572
(*dev->ring_buffer)[dev->ring_tail].cmd[1],
573
(*dev->ring_buffer)[dev->ring_tail].cmd[2],
574
(*dev->ring_buffer)[dev->ring_tail].cmd[3],
575
(*dev->ring_buffer)[dev->ring_tail].cmd[4],
576
(*dev->ring_buffer)[dev->ring_tail].cmd[5],
577
(*dev->ring_buffer)[dev->ring_tail].cmd[6],
578
(*dev->ring_buffer)[dev->ring_tail].cmd[7]);
580
if (((*dev->ring_buffer)[dev->ring_tail].cmd[6] != 0 &&
581
(*dev->ring_buffer)[next_tail].cmd[6] != 0) &&
582
((newwheel > 0 && oldwheel > 0) ||
583
(newwheel < 0 && oldwheel < 0)) &&
584
((*dev->ring_buffer)[dev->ring_tail].cmd[2] ==
585
(*dev->ring_buffer)[next_tail].cmd[2]) &&
586
((*dev->ring_buffer)[dev->ring_tail].cmd[3] ==
587
(*dev->ring_buffer)[next_tail].cmd[3]) &&
588
((*dev->ring_buffer)[dev->ring_tail].cmd[4] ==
589
(*dev->ring_buffer)[next_tail].cmd[4]) &&
590
((*dev->ring_buffer)[dev->ring_tail].cmd[5] ==
591
(*dev->ring_buffer)[next_tail].cmd[5])) {
592
dbg_info(&dev->intf->dev,
593
"%s: should compress: "
594
"%02x%02x%02x%02x%02x%02x%02x%02x\n",
596
(*dev->ring_buffer)[dev->ring_tail].
598
(*dev->ring_buffer)[dev->ring_tail].
600
(*dev->ring_buffer)[dev->ring_tail].
602
(*dev->ring_buffer)[dev->ring_tail].
604
(*dev->ring_buffer)[dev->ring_tail].
606
(*dev->ring_buffer)[dev->ring_tail].
608
(*dev->ring_buffer)[dev->ring_tail].
610
(*dev->ring_buffer)[dev->ring_tail].
612
newwheel += oldwheel;
613
if (oldwheel > 0 && !(newwheel > 0)) {
617
if (oldwheel < 0 && !(newwheel < 0)) {
622
(*dev->ring_buffer)[next_tail].cmd[6] =
624
dev->ring_tail = next_tail;
626
(dev->ring_tail + 1) % ring_buffer_size;
631
#endif /* COMPRESS_WHEEL_EVENTS */
634
&(*dev->ring_buffer)[dev->ring_tail], 8)) {
638
dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
640
dbg_info(&dev->intf->dev,
641
"%s: head, tail are %x, %x\n",
642
__func__, dev->ring_head, dev->ring_tail);
647
/* if (copy_to_user(buffer, &(*dev->ring_buffer)[dev->ring_tail], 8)) { */
652
dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
653
dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n",
654
__func__, dev->ring_head, dev->ring_tail);
657
#endif /* BUFFERED_READS */
660
/* unlock the device */
668
* usb_tranzport_write
670
static ssize_t usb_tranzport_write(struct file *file,
671
const char __user *buffer, size_t count,
674
struct usb_tranzport *dev;
675
size_t bytes_to_write;
678
dev = file->private_data;
680
/* verify that we actually have some data to write */
684
/* lock this object */
685
if (down_interruptible(&dev->sem)) {
686
retval = -ERESTARTSYS;
689
/* verify that the device wasn't unplugged */
690
if (dev->intf == NULL) {
692
err("No device or device unplugged %d\n", retval);
696
/* wait until previous transfer is finished */
697
if (dev->interrupt_out_busy) {
698
if (file->f_flags & O_NONBLOCK) {
702
retval = wait_event_interruptible(dev->write_wait,
703
!dev->interrupt_out_busy);
708
/* write the data into interrupt_out_buffer from userspace */
709
bytes_to_write = min(count,
711
dev->interrupt_out_endpoint_size);
712
if (bytes_to_write < count)
713
dev_warn(&dev->intf->dev,
714
"Write buffer overflow, %zd bytes dropped\n",
715
count - bytes_to_write);
717
dbg_info(&dev->intf->dev,
718
"%s: count = %zd, bytes_to_write = %zd\n", __func__,
719
count, bytes_to_write);
721
if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
726
if (dev->interrupt_out_endpoint == NULL) {
727
err("Endpoint should not be be null! \n");
731
/* send off the urb */
732
usb_fill_int_urb(dev->interrupt_out_urb,
733
interface_to_usbdev(dev->intf),
734
usb_sndintpipe(interface_to_usbdev(dev->intf),
735
dev->interrupt_out_endpoint->
737
dev->interrupt_out_buffer, bytes_to_write,
738
usb_tranzport_interrupt_out_callback, dev,
739
dev->interrupt_out_interval);
741
dev->interrupt_out_busy = 1;
744
retval = usb_submit_urb(dev->interrupt_out_urb, GFP_KERNEL);
746
dev->interrupt_out_busy = 0;
747
err("Couldn't submit interrupt_out_urb %d\n", retval);
750
retval = bytes_to_write;
753
/* unlock the device */
760
/* file operations needed when we register this driver */
761
static const struct file_operations usb_tranzport_fops = {
762
.owner = THIS_MODULE,
763
.read = usb_tranzport_read,
764
.write = usb_tranzport_write,
765
.open = usb_tranzport_open,
766
.release = usb_tranzport_release,
767
.poll = usb_tranzport_poll,
771
* usb class driver info in order to get a minor number from the usb core,
772
* and to have the device registered with the driver core
774
static struct usb_class_driver usb_tranzport_class = {
775
.name = "tranzport%d",
776
.fops = &usb_tranzport_fops,
777
.minor_base = USB_TRANZPORT_MINOR_BASE,
781
* usb_tranzport_probe
783
* Called by the usb core when a new device is connected that it thinks
784
* this driver might be interested in.
786
static int usb_tranzport_probe(struct usb_interface *intf,
787
const struct usb_device_id *id) {
788
struct usb_device *udev = interface_to_usbdev(intf);
789
struct usb_tranzport *dev = NULL;
790
struct usb_host_interface *iface_desc;
791
struct usb_endpoint_descriptor *endpoint;
794
int retval = -ENOMEM;
796
/* allocate memory for our device state and intialize it */
798
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
800
dev_err(&intf->dev, "Out of memory\n");
803
init_MUTEX(&dev->sem);
805
init_waitqueue_head(&dev->read_wait);
806
init_waitqueue_head(&dev->write_wait);
808
iface_desc = intf->cur_altsetting;
810
/* set up the endpoint information */
811
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
812
endpoint = &iface_desc->endpoint[i].desc;
814
if (usb_endpoint_is_int_in(endpoint))
815
dev->interrupt_in_endpoint = endpoint;
817
if (usb_endpoint_is_int_out(endpoint))
818
dev->interrupt_out_endpoint = endpoint;
820
if (dev->interrupt_in_endpoint == NULL) {
821
dev_err(&intf->dev, "Interrupt in endpoint not found\n");
824
if (dev->interrupt_out_endpoint == NULL)
826
"Interrupt out endpoint not found"
827
"(using control endpoint instead)\n");
829
dev->interrupt_in_endpoint_size =
830
le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
832
if (dev->interrupt_in_endpoint_size != 8)
833
dev_warn(&intf->dev, "Interrupt in endpoint size is not 8!\n");
835
if (ring_buffer_size == 0)
836
ring_buffer_size = RING_BUFFER_SIZE;
837
true_size = min(ring_buffer_size, RING_BUFFER_SIZE);
839
/* FIXME - there are more usb_alloc routines for dma correctness.
843
kmalloc((true_size * sizeof(struct tranzport_cmd)) + 8, GFP_KERNEL);
845
if (!dev->ring_buffer) {
847
"Couldn't allocate ring_buffer size %d\n", true_size);
850
dev->interrupt_in_buffer =
851
kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
852
if (!dev->interrupt_in_buffer) {
853
dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
856
dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
857
if (!dev->interrupt_in_urb) {
858
dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
861
dev->interrupt_out_endpoint_size =
862
dev->interrupt_out_endpoint ?
863
le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
864
udev->descriptor.bMaxPacketSize0;
866
if (dev->interrupt_out_endpoint_size != 8)
868
"Interrupt out endpoint size is not 8!)\n");
870
dev->interrupt_out_buffer =
871
kmalloc(write_buffer_size * dev->interrupt_out_endpoint_size,
873
if (!dev->interrupt_out_buffer) {
874
dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
877
dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
878
if (!dev->interrupt_out_urb) {
879
dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
882
dev->interrupt_in_interval =
883
min_interrupt_in_interval >
884
dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval
885
: dev->interrupt_in_endpoint->bInterval;
887
if (dev->interrupt_out_endpoint) {
888
dev->interrupt_out_interval =
889
min_interrupt_out_interval >
890
dev->interrupt_out_endpoint->bInterval ?
891
min_interrupt_out_interval :
892
dev->interrupt_out_endpoint->bInterval;
895
/* we can register the device now, as it is ready */
896
usb_set_intfdata(intf, dev);
898
retval = usb_register_dev(intf, &usb_tranzport_class);
900
/* something prevented us from registering this driver */
902
"Not able to get a minor for this device.\n");
903
usb_set_intfdata(intf, NULL);
907
retval = device_create_file(&intf->dev, &dev_attr_compress_wheel);
910
retval = device_create_file(&intf->dev, &dev_attr_enable);
913
retval = device_create_file(&intf->dev, &dev_attr_offline);
917
/* let the user know what node this device is now attached to */
919
"Tranzport Device #%d now attached to major %d minor %d\n",
920
(intf->minor - USB_TRANZPORT_MINOR_BASE), USB_MAJOR,
927
usb_tranzport_delete(dev);
932
* usb_tranzport_disconnect
934
* Called by the usb core when the device is removed from the system.
936
static void usb_tranzport_disconnect(struct usb_interface *intf)
938
struct usb_tranzport *dev;
940
mutex_lock(&disconnect_mutex);
941
dev = usb_get_intfdata(intf);
942
usb_set_intfdata(intf, NULL);
945
/* give back our minor */
946
usb_deregister_dev(intf, &usb_tranzport_class);
948
/* if the device is not opened, then we clean up right now */
949
if (!dev->open_count) {
951
usb_tranzport_delete(dev);
957
mutex_unlock(&disconnect_mutex);
959
dev_info(&intf->dev, "Tranzport Surface #%d now disconnected\n",
960
(minor - USB_TRANZPORT_MINOR_BASE));
963
/* usb specific object needed to register this driver with the usb subsystem */
964
static struct usb_driver usb_tranzport_driver = {
966
.probe = usb_tranzport_probe,
967
.disconnect = usb_tranzport_disconnect,
968
.id_table = usb_tranzport_table,
974
static int __init usb_tranzport_init(void)
978
/* register this driver with the USB subsystem */
979
retval = usb_register(&usb_tranzport_driver);
981
err("usb_register failed for the " __FILE__
982
" driver. Error number %d\n", retval);
989
static void __exit usb_tranzport_exit(void)
991
/* deregister this driver with the USB subsystem */
992
usb_deregister(&usb_tranzport_driver);
995
module_init(usb_tranzport_init);
996
module_exit(usb_tranzport_exit);