aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Täht <d@teklibre.com>2009-01-20 09:33:20 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-04-03 17:53:31 -0400
commit7c68d6b7171aa2f3d0c68b9ff54a2e1f0f0e228f (patch)
tree46314471dabb3834e29e4a7efc6b64c0b3e0947a
parentd44ca7af9e79abf4e80514583734cffed1117ee1 (diff)
Staging: frontier: Make checkpatch.pl considerably happier with tranzport driver.
Signed-off-by: David Täht <d@teklibre.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/frontier/tranzport.c729
1 files changed, 414 insertions, 315 deletions
diff --git a/drivers/staging/frontier/tranzport.c b/drivers/staging/frontier/tranzport.c
index 79abb6b16f74..4ed8ac8b6430 100644
--- a/drivers/staging/frontier/tranzport.c
+++ b/drivers/staging/frontier/tranzport.c
@@ -18,7 +18,7 @@
18 * 18 *
19 */ 19 */
20 20
21/** 21/*
22 * This driver uses a ring buffer for time critical reading of 22 * This driver uses a ring buffer for time critical reading of
23 * interrupt in reports and provides read and write methods for 23 * interrupt in reports and provides read and write methods for
24 * raw interrupt reports. 24 * raw interrupt reports.
@@ -30,7 +30,7 @@
30 * as we only have 17 commands for the tranzport. In particular this is 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 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. 32 * can be buffered up before the light change makes it to the interface.
33*/ 33 */
34 34
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/errno.h> 36#include <linux/errno.h>
@@ -40,56 +40,47 @@
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41#include <linux/version.h> 41#include <linux/version.h>
42 42
43#include <asm/uaccess.h> 43#include <linux/uaccess.h>
44#include <linux/input.h> 44#include <linux/input.h>
45#include <linux/usb.h> 45#include <linux/usb.h>
46#include <linux/poll.h> 46#include <linux/poll.h>
47 47
48#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
49#include frontier_compat.h
50#endif
51
52/* Define these values to match your devices */ 48/* Define these values to match your devices */
53#define VENDOR_ID 0x165b 49#define VENDOR_ID 0x165b
54#define PRODUCT_ID 0x8101 50#define PRODUCT_ID 0x8101
55 51
56#ifdef CONFIG_USB_DYNAMIC_MINORS 52#ifdef CONFIG_USB_DYNAMIC_MINORS
57#define USB_TRANZPORT_MINOR_BASE 0 53#define USB_TRANZPORT_MINOR_BASE 0
58#else 54#else /* FIXME 176 - is the ldusb driver's minor - apply for a minor soon */
59// FIXME 176 - is the ldusb driver's minor - apply for a minor soon
60#define USB_TRANZPORT_MINOR_BASE 177 55#define USB_TRANZPORT_MINOR_BASE 177
61#endif 56#endif
62 57
63/* table of devices that work with this driver */ 58/* table of devices that work with this driver */
64static struct usb_device_id usb_tranzport_table [] = { 59static struct usb_device_id usb_tranzport_table[] = {
65 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) }, 60 {USB_DEVICE(VENDOR_ID, PRODUCT_ID)},
66 { } /* Terminating entry */ 61 {} /* Terminating entry */
67}; 62};
68 63
69MODULE_DEVICE_TABLE(usb, usb_tranzport_table); 64MODULE_DEVICE_TABLE(usb, usb_tranzport_table);
70MODULE_VERSION("0.33"); 65MODULE_VERSION("0.34");
71MODULE_AUTHOR("Mike Taht <m@taht.net>"); 66MODULE_AUTHOR("Mike Taht <m@taht.net>");
72MODULE_DESCRIPTION("Tranzport USB Driver"); 67MODULE_DESCRIPTION("Tranzport USB Driver");
73MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
74MODULE_SUPPORTED_DEVICE("Frontier Designs Tranzport Control Surface"); 69MODULE_SUPPORTED_DEVICE("Frontier Designs Tranzport Control Surface");
75 70
76/* These two aren't done yet */
77
78#define SUPPRESS_EXTRA_ONLINE_EVENTS 0
79#define BUFFERED_WRITES 0
80
81#define SUPPRESS_EXTRA_OFFLINE_EVENTS 1 71#define SUPPRESS_EXTRA_OFFLINE_EVENTS 1
82#define COMPRESS_WHEEL_EVENTS 1 72#define COMPRESS_WHEEL_EVENTS 1
83#define BUFFERED_READS 1 73#define BUFFERED_READS 1
84#define RING_BUFFER_SIZE 1000 74#define RING_BUFFER_SIZE 1000
85#define WRITE_BUFFER_SIZE 34 75#define WRITE_BUFFER_SIZE 34
86#define TRANZPORT_USB_TIMEOUT 10 76#define TRANZPORT_USB_TIMEOUT 10
77#define TRANZPORT_DEBUG 0
87 78
88 79static int debug = TRANZPORT_DEBUG;
89static int debug = 0;
90 80
91/* Use our own dbg macro */ 81/* Use our own dbg macro */
92#define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) 82#define dbg_info(dev, format, arg...) do \
83 { if (debug) dev_info(dev , format , ## arg); } while (0)
93 84
94/* Module parameters */ 85/* Module parameters */
95 86
@@ -102,13 +93,13 @@ MODULE_PARM_DESC(debug, "Debug enabled or not");
102 93
103static int ring_buffer_size = RING_BUFFER_SIZE; 94static int ring_buffer_size = RING_BUFFER_SIZE;
104 95
105module_param(ring_buffer_size, int, S_IRUGO); 96module_param(ring_buffer_size, int, S_IRUGO);
106MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports"); 97MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size in reports");
107 98
108/* The write_buffer can one day contain more than one interrupt out transfer. 99/* The write_buffer can one day contain more than one interrupt out transfer.
109 */ 100 */
110static int write_buffer_size = WRITE_BUFFER_SIZE; 101static int write_buffer_size = WRITE_BUFFER_SIZE;
111module_param(write_buffer_size, int, S_IRUGO); 102module_param(write_buffer_size, int, S_IRUGO);
112MODULE_PARM_DESC(write_buffer_size, "Write buffer size"); 103MODULE_PARM_DESC(write_buffer_size, "Write buffer size");
113 104
114/* 105/*
@@ -118,14 +109,16 @@ MODULE_PARM_DESC(write_buffer_size, "Write buffer size");
118 109
119static int min_interrupt_in_interval = TRANZPORT_USB_TIMEOUT; 110static int min_interrupt_in_interval = TRANZPORT_USB_TIMEOUT;
120module_param(min_interrupt_in_interval, int, 0); 111module_param(min_interrupt_in_interval, int, 0);
121MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms"); 112MODULE_PARM_DESC(min_interrupt_in_interval,
113 "Minimum interrupt in interval in ms");
122 114
123static int min_interrupt_out_interval = TRANZPORT_USB_TIMEOUT; 115static int min_interrupt_out_interval = TRANZPORT_USB_TIMEOUT;
124module_param(min_interrupt_out_interval, int, 0); 116module_param(min_interrupt_out_interval, int, 0);
125MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms"); 117MODULE_PARM_DESC(min_interrupt_out_interval,
118 "Minimum interrupt out interval in ms");
126 119
127struct tranzport_cmd { 120struct tranzport_cmd {
128 unsigned char cmd[8]; 121 unsigned char cmd[8];
129}; 122};
130 123
131enum LightID { 124enum LightID {
@@ -136,50 +129,45 @@ enum LightID {
136 LightAnysolo, 129 LightAnysolo,
137 LightLoop, 130 LightLoop,
138 LightPunch 131 LightPunch
139 }; 132};
140 133
141/* Structure to hold all of our device specific stuff */ 134/* Structure to hold all of our device specific stuff */
142 135
143struct usb_tranzport { 136struct usb_tranzport {
144 struct semaphore sem; /* locks this structure */ 137 struct semaphore sem; /* locks this structure */
145 struct usb_interface* intf; /* save off the usb interface pointer */ 138 struct usb_interface *intf; /* save off the usb interface pointer */
146 139 int open_count; /* number of times this port opened */
147 int open_count; /* number of times this port has been opened */ 140 struct tranzport_cmd (*ring_buffer)[RING_BUFFER_SIZE];
148 141 unsigned int ring_head;
149 struct tranzport_cmd (*ring_buffer)[RING_BUFFER_SIZE]; /* just make c happy */ 142 unsigned int ring_tail;
150 unsigned int ring_head; 143 wait_queue_head_t read_wait;
151 unsigned int ring_tail; 144 wait_queue_head_t write_wait;
152 145 unsigned char *interrupt_in_buffer;
153 wait_queue_head_t read_wait; 146 struct usb_endpoint_descriptor *interrupt_in_endpoint;
154 wait_queue_head_t write_wait; 147 struct urb *interrupt_in_urb;
155 148 int interrupt_in_interval;
156 unsigned char* interrupt_in_buffer; 149 size_t interrupt_in_endpoint_size;
157 struct usb_endpoint_descriptor* interrupt_in_endpoint; 150 int interrupt_in_running;
158 struct urb* interrupt_in_urb; 151 int interrupt_in_done;
159 int interrupt_in_interval; 152 char *interrupt_out_buffer;
160 size_t interrupt_in_endpoint_size; 153 struct usb_endpoint_descriptor *interrupt_out_endpoint;
161 int interrupt_in_running; 154 struct urb *interrupt_out_urb;
162 int interrupt_in_done; 155 int interrupt_out_interval;
163 156 size_t interrupt_out_endpoint_size;
164 char* interrupt_out_buffer; 157 int interrupt_out_busy;
165 struct usb_endpoint_descriptor* interrupt_out_endpoint;
166 struct urb* interrupt_out_urb;
167 int interrupt_out_interval;
168 size_t interrupt_out_endpoint_size;
169 int interrupt_out_busy;
170 158
171 /* Sysfs and translation support */ 159 /* Sysfs and translation support */
172 160
173 int event; /* alternate interface to events */ 161 int event; /* alternate interface to events */
174 int wheel; /* - for negative, 0 for none, + for positive */ 162 int wheel; /* - for negative, 0 for none, + for positive */
175 unsigned char dump_state; /* 0 if disabled 1 if enabled */ 163 unsigned char dump_state; /* 0 if disabled 1 if enabled */
176 unsigned char enable; /* 0 if disabled 1 if enabled */ 164 unsigned char enable; /* 0 if disabled 1 if enabled */
177 unsigned char offline; /* if the device is out of range or asleep */ 165 unsigned char offline; /* if the device is out of range or asleep */
178 unsigned char compress_wheel; /* flag to compress wheel events */ 166 unsigned char compress_wheel; /* flag to compress wheel events */
179 unsigned char light; /* 7 bits used */ 167 unsigned char light; /* 7 bits used */
180 unsigned char last_cmd[8]; 168 unsigned char last_cmd[8];
181 unsigned char last_input[8]; 169 unsigned char last_input[8];
182 unsigned char screen[40]; // We'll also have cells 170 unsigned char screen[40]; /* We'll also have cells */
183 171
184}; 172};
185 173
@@ -205,27 +193,30 @@ static void usb_tranzport_abort_transfers(struct usb_tranzport *dev)
205 usb_kill_urb(dev->interrupt_out_urb); 193 usb_kill_urb(dev->interrupt_out_urb);
206} 194}
207 195
208// FIXME ~light not good enough or correct - need atomic set_bit 196/* FIXME ~light not good enough or correct - need atomic set_bit */
209 197
210#define show_set_light(value) \ 198#define show_set_light(value) \
211static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 199 static ssize_t show_##value( \
212{ \ 200 struct device *dev, struct device_attribute *attr, char *buf) \
213 struct usb_interface *intf = to_usb_interface(dev); \ 201 { \
214 struct usb_tranzport *t = usb_get_intfdata(intf); \ 202 struct usb_interface *intf = to_usb_interface(dev); \
215 enum LightID light = value; \ 203 struct usb_tranzport *t = usb_get_intfdata(intf); \
216 int temp = (1 && (t->light & (1 << light))); \ 204 enum LightID light = value; \
217 return sprintf(buf, "%d\n", temp ); \ 205 int temp = (1 && (t->light & (1 << light))); \
218} \ 206 return sprintf(buf, "%d\n", temp); \
219static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 207 } \
220{ \ 208 static ssize_t set_##value( \
221 struct usb_interface *intf = to_usb_interface(dev); \ 209 struct device *dev, struct device_attribute *attr, \
222 struct usb_tranzport *t = usb_get_intfdata(intf); \ 210 const char *buf, size_t count) \
223 int temp = simple_strtoul(buf, NULL, 10); \ 211 { \
224 enum LightID light = (temp << value) & (t->light << value); \ 212 struct usb_interface *intf = to_usb_interface(dev); \
225 t->light = (t->light & ~light) ; \ 213 struct usb_tranzport *t = usb_get_intfdata(intf); \
226 return count; \ 214 int temp = simple_strtoul(buf, NULL, 10); \
227} \ 215 enum LightID light = (temp << value) & (t->light << value); \
228static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 216 t->light = (t->light & ~light) ; \
217 return count; \
218 } \
219 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
229 220
230show_set_light(LightRecord); 221show_set_light(LightRecord);
231show_set_light(LightTrackrec); 222show_set_light(LightTrackrec);
@@ -235,25 +226,25 @@ show_set_light(LightAnysolo);
235show_set_light(LightLoop); 226show_set_light(LightLoop);
236show_set_light(LightPunch); 227show_set_light(LightPunch);
237 228
238 229#define show_set_int(value) \
239#define show_set_int(value) \ 230 static ssize_t show_##value(struct device *dev, \
240static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 231 struct device_attribute *attr, char *buf) \
241{ \ 232 { \
242 struct usb_interface *intf = to_usb_interface(dev); \ 233 struct usb_interface *intf = to_usb_interface(dev); \
243 struct usb_tranzport *t = usb_get_intfdata(intf); \ 234 struct usb_tranzport *t = usb_get_intfdata(intf); \
244 \ 235 return sprintf(buf, "%d\n", t->value); \
245 return sprintf(buf, "%d\n", t->value); \ 236 } \
246} \ 237 static ssize_t set_##value(struct device *dev, \
247static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 238 struct device_attribute *attr, \
248{ \ 239 const char *buf, size_t count) \
249 struct usb_interface *intf = to_usb_interface(dev); \ 240 { \
250 struct usb_tranzport *t = usb_get_intfdata(intf); \ 241 struct usb_interface *intf = to_usb_interface(dev); \
251 int temp = simple_strtoul(buf, NULL, 10); \ 242 struct usb_tranzport *t = usb_get_intfdata(intf); \
252 \ 243 int temp = simple_strtoul(buf, NULL, 10); \
253 t->value = temp; \ 244 t->value = temp; \
254 return count; \ 245 return count; \
255} \ 246 } \
256static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 247 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
257 248
258show_set_int(enable); 249show_set_int(enable);
259show_set_int(offline); 250show_set_int(offline);
@@ -262,27 +253,27 @@ show_set_int(dump_state);
262show_set_int(wheel); 253show_set_int(wheel);
263show_set_int(event); 254show_set_int(event);
264 255
265#define show_set_cmd(value) \ 256#define show_set_cmd(value) \
266static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 257 static ssize_t show_##value(struct device *dev, \
267{ \ 258 struct device_attribute *attr, char *buf) \
268 struct usb_interface *intf = to_usb_interface(dev); \ 259 { \
269 struct usb_tranzport *t = usb_get_intfdata(intf); \ 260 struct usb_interface *intf = to_usb_interface(dev); \
261 struct usb_tranzport *t = usb_get_intfdata(intf); \
270 \ 262 \
271 return sprintf(buf, "%d\n", t->value); \ 263 return sprintf(buf, "%d\n", t->value); \
272} \ 264 } \
273static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 265 static ssize_t set_##value(struct device *dev, \
274{ \ 266 struct device_attribute *attr, \
275 struct usb_interface *intf = to_usb_interface(dev); \ 267 const char *buf, size_t count) \
276 struct usb_tranzport *t = usb_get_intfdata(intf); \ 268 { \
277 int temp = simple_strtoul(buf, NULL, 10); \ 269 struct usb_interface *intf = to_usb_interface(dev); \
270 struct usb_tranzport *t = usb_get_intfdata(intf); \
271 int temp = simple_strtoul(buf, NULL, 10); \
278 \ 272 \
279 t->value = temp; \ 273 t->value = temp; \
280 return count; \ 274 return count; \
281} \ 275 } \
282static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value); 276 static DEVICE_ATTR(value, S_IWUGO | S_IRUGO, show_##value, set_##value);
283
284
285
286 277
287/** 278/**
288 * usb_tranzport_delete 279 * usb_tranzport_delete
@@ -291,22 +282,21 @@ static void usb_tranzport_delete(struct usb_tranzport *dev)
291{ 282{
292 usb_tranzport_abort_transfers(dev); 283 usb_tranzport_abort_transfers(dev);
293 /* This is just too twisted to be correct */ 284 /* This is just too twisted to be correct */
294 if(dev->intf != NULL) { 285 if (dev->intf != NULL) {
295 device_remove_file(&dev->intf->dev, &dev_attr_LightRecord); 286 device_remove_file(&dev->intf->dev, &dev_attr_LightRecord);
296 device_remove_file(&dev->intf->dev, &dev_attr_LightTrackrec); 287 device_remove_file(&dev->intf->dev, &dev_attr_LightTrackrec);
297 device_remove_file(&dev->intf->dev, &dev_attr_LightTrackmute); 288 device_remove_file(&dev->intf->dev, &dev_attr_LightTrackmute);
298 device_remove_file(&dev->intf->dev, &dev_attr_LightTracksolo); 289 device_remove_file(&dev->intf->dev, &dev_attr_LightTracksolo);
299 device_remove_file(&dev->intf->dev, &dev_attr_LightTrackmute); 290 device_remove_file(&dev->intf->dev, &dev_attr_LightTrackmute);
300 device_remove_file(&dev->intf->dev, &dev_attr_LightAnysolo); 291 device_remove_file(&dev->intf->dev, &dev_attr_LightAnysolo);
301 device_remove_file(&dev->intf->dev, &dev_attr_LightLoop); 292 device_remove_file(&dev->intf->dev, &dev_attr_LightLoop);
302 device_remove_file(&dev->intf->dev, &dev_attr_LightPunch); 293 device_remove_file(&dev->intf->dev, &dev_attr_LightPunch);
303 device_remove_file(&dev->intf->dev, &dev_attr_wheel); 294 device_remove_file(&dev->intf->dev, &dev_attr_wheel);
304 device_remove_file(&dev->intf->dev, &dev_attr_enable); 295 device_remove_file(&dev->intf->dev, &dev_attr_enable);
305 device_remove_file(&dev->intf->dev, &dev_attr_event); 296 device_remove_file(&dev->intf->dev, &dev_attr_event);
306 device_remove_file(&dev->intf->dev, &dev_attr_offline); 297 device_remove_file(&dev->intf->dev, &dev_attr_offline);
307 device_remove_file(&dev->intf->dev, &dev_attr_compress_wheel); 298 device_remove_file(&dev->intf->dev, &dev_attr_compress_wheel);
308 299 device_remove_file(&dev->intf->dev, &dev_attr_dump_state);
309 device_remove_file(&dev->intf->dev, &dev_attr_dump_state);
310 } 300 }
311 301
312 /* free data structures */ 302 /* free data structures */
@@ -330,37 +320,56 @@ static void usb_tranzport_interrupt_in_callback(struct urb *urb)
330 320
331 if (urb->status) { 321 if (urb->status) {
332 if (urb->status == -ENOENT || 322 if (urb->status == -ENOENT ||
333 urb->status == -ECONNRESET || 323 urb->status == -ECONNRESET ||
334 urb->status == -ESHUTDOWN) { 324 urb->status == -ESHUTDOWN) {
335 goto exit; 325 goto exit;
336 } else { 326 } else {
337 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", 327 dbg_info(&dev->intf->dev,
328 "%s: nonzero status received: %d\n",
338 __func__, urb->status); 329 __func__, urb->status);
339 goto resubmit; /* maybe we can recover */ 330 goto resubmit; /* maybe we can recover */
340 } 331 }
341 } 332 }
342 333
343 if (urb->actual_length != 8) { 334 if (urb->actual_length != 8) {
344 dev_warn(&dev->intf->dev, 335 dev_warn(&dev->intf->dev,
345 "Urb length was %d bytes!! Do something intelligent \n", urb->actual_length); 336 "Urb length was %d bytes!!"
337 "Do something intelligent \n",
338 urb->actual_length);
346 } else { 339 } else {
347 dbg_info(&dev->intf->dev, "%s: received: %02x%02x%02x%02x%02x%02x%02x%02x\n", 340 dbg_info(&dev->intf->dev,
348 __func__, dev->interrupt_in_buffer[0],dev->interrupt_in_buffer[1],dev->interrupt_in_buffer[2],dev->interrupt_in_buffer[3],dev->interrupt_in_buffer[4],dev->interrupt_in_buffer[5],dev->interrupt_in_buffer[6],dev->interrupt_in_buffer[7]); 341 "%s: received: %02x%02x%02x%02x%02x%02x%02x%02x\n",
342 __func__, dev->interrupt_in_buffer[0],
343 dev->interrupt_in_buffer[1],
344 dev->interrupt_in_buffer[2],
345 dev->interrupt_in_buffer[3],
346 dev->interrupt_in_buffer[4],
347 dev->interrupt_in_buffer[5],
348 dev->interrupt_in_buffer[6],
349 dev->interrupt_in_buffer[7]);
349#if SUPPRESS_EXTRA_OFFLINE_EVENTS 350#if SUPPRESS_EXTRA_OFFLINE_EVENTS
350 if(dev->offline == 2 && dev->interrupt_in_buffer[1] == 0xff) { goto resubmit; } 351 if (dev->offline == 2 && dev->interrupt_in_buffer[1] == 0xff)
351 if(dev->offline == 1 && dev->interrupt_in_buffer[1] == 0xff) { dev->offline = 2; goto resubmit; } 352 goto resubmit;
353 if (dev->offline == 1 && dev->interrupt_in_buffer[1] == 0xff) {
354 dev->offline = 2;
355 goto resubmit;
356 }
352 357
353/* Always pass one offline event up the stack */ 358 /* Always pass one offline event up the stack */
354 if(dev->offline > 0 && dev->interrupt_in_buffer[1] != 0xff) { dev->offline = 0; } 359 if (dev->offline > 0 && dev->interrupt_in_buffer[1] != 0xff)
355 if(dev->offline == 0 && dev->interrupt_in_buffer[1] == 0xff) { dev->offline = 1; } 360 dev->offline = 0;
361 if (dev->offline == 0 && dev->interrupt_in_buffer[1] == 0xff)
362 dev->offline = 1;
356 363
357#endif 364#endif /* SUPPRESS_EXTRA_OFFLINE_EVENTS */
358 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n", __func__,dev->ring_head,dev->ring_tail); 365 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n",
366 __func__, dev->ring_head, dev->ring_tail);
359 367
360 next_ring_head = (dev->ring_head+1) % ring_buffer_size; 368 next_ring_head = (dev->ring_head + 1) % ring_buffer_size;
361 369
362 if (next_ring_head != dev->ring_tail) { 370 if (next_ring_head != dev->ring_tail) {
363 memcpy(&((*dev->ring_buffer)[dev->ring_head]), dev->interrupt_in_buffer, urb->actual_length); 371 memcpy(&((*dev->ring_buffer)[dev->ring_head]),
372 dev->interrupt_in_buffer, urb->actual_length);
364 dev->ring_head = next_ring_head; 373 dev->ring_head = next_ring_head;
365 retval = 0; 374 retval = 0;
366 memset(dev->interrupt_in_buffer, 0, urb->actual_length); 375 memset(dev->interrupt_in_buffer, 0, urb->actual_length);
@@ -373,7 +382,7 @@ static void usb_tranzport_interrupt_in_callback(struct urb *urb)
373 } 382 }
374 383
375resubmit: 384resubmit:
376 /* resubmit if we're still running */ 385/* resubmit if we're still running */
377 if (dev->interrupt_in_running && dev->intf) { 386 if (dev->interrupt_in_running && dev->intf) {
378 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC); 387 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_ATOMIC);
379 if (retval) 388 if (retval)
@@ -392,19 +401,17 @@ exit:
392static void usb_tranzport_interrupt_out_callback(struct urb *urb) 401static void usb_tranzport_interrupt_out_callback(struct urb *urb)
393{ 402{
394 struct usb_tranzport *dev = urb->context; 403 struct usb_tranzport *dev = urb->context;
395
396 /* sync/async unlink faults aren't errors */ 404 /* sync/async unlink faults aren't errors */
397 if (urb->status && !(urb->status == -ENOENT || 405 if (urb->status && !(urb->status == -ENOENT ||
398 urb->status == -ECONNRESET || 406 urb->status == -ECONNRESET ||
399 urb->status == -ESHUTDOWN)) 407 urb->status == -ESHUTDOWN))
400 dbg_info(&dev->intf->dev, 408 dbg_info(&dev->intf->dev,
401 "%s - nonzero write interrupt status received: %d\n", 409 "%s - nonzero write interrupt status received: %d\n",
402 __func__, urb->status); 410 __func__, urb->status);
403 411
404 dev->interrupt_out_busy = 0; 412 dev->interrupt_out_busy = 0;
405 wake_up_interruptible(&dev->write_wait); 413 wake_up_interruptible(&dev->write_wait);
406} 414}
407
408/** 415/**
409 * usb_tranzport_open 416 * usb_tranzport_open
410 */ 417 */
@@ -424,7 +431,7 @@ static int usb_tranzport_open(struct inode *inode, struct file *file)
424 431
425 if (!interface) { 432 if (!interface) {
426 err("%s - error, can't find device for minor %d\n", 433 err("%s - error, can't find device for minor %d\n",
427 __func__, subminor); 434 __func__, subminor);
428 retval = -ENODEV; 435 retval = -ENODEV;
429 goto unlock_disconnect_exit; 436 goto unlock_disconnect_exit;
430 } 437 }
@@ -453,14 +460,14 @@ static int usb_tranzport_open(struct inode *inode, struct file *file)
453 dev->ring_head = 0; 460 dev->ring_head = 0;
454 dev->ring_tail = 0; 461 dev->ring_tail = 0;
455 usb_fill_int_urb(dev->interrupt_in_urb, 462 usb_fill_int_urb(dev->interrupt_in_urb,
456 interface_to_usbdev(interface), 463 interface_to_usbdev(interface),
457 usb_rcvintpipe(interface_to_usbdev(interface), 464 usb_rcvintpipe(interface_to_usbdev(interface),
458 dev->interrupt_in_endpoint->bEndpointAddress), 465 dev->interrupt_in_endpoint->
459 dev->interrupt_in_buffer, 466 bEndpointAddress),
460 dev->interrupt_in_endpoint_size, 467 dev->interrupt_in_buffer,
461 usb_tranzport_interrupt_in_callback, 468 dev->interrupt_in_endpoint_size,
462 dev, 469 usb_tranzport_interrupt_in_callback, dev,
463 dev->interrupt_in_interval); 470 dev->interrupt_in_interval);
464 471
465 dev->interrupt_in_running = 1; 472 dev->interrupt_in_running = 1;
466 dev->interrupt_in_done = 0; 473 dev->interrupt_in_done = 0;
@@ -470,7 +477,8 @@ static int usb_tranzport_open(struct inode *inode, struct file *file)
470 477
471 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL); 478 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
472 if (retval) { 479 if (retval) {
473 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval); 480 dev_err(&interface->dev,
481 "Couldn't submit interrupt_in_urb %d\n", retval);
474 dev->interrupt_in_running = 0; 482 dev->interrupt_in_running = 0;
475 dev->open_count = 0; 483 dev->open_count = 0;
476 goto unlock_exit; 484 goto unlock_exit;
@@ -479,7 +487,6 @@ static int usb_tranzport_open(struct inode *inode, struct file *file)
479 /* save device in the file's private structure */ 487 /* save device in the file's private structure */
480 file->private_data = dev; 488 file->private_data = dev;
481 489
482
483unlock_exit: 490unlock_exit:
484 up(&dev->sem); 491 up(&dev->sem);
485 492
@@ -525,7 +532,9 @@ static int usb_tranzport_release(struct inode *inode, struct file *file)
525 532
526 /* wait until write transfer is finished */ 533 /* wait until write transfer is finished */
527 if (dev->interrupt_out_busy) 534 if (dev->interrupt_out_busy)
528 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ); 535 wait_event_interruptible_timeout(dev->write_wait,
536 !dev->interrupt_out_busy,
537 2 * HZ);
529 usb_tranzport_abort_transfers(dev); 538 usb_tranzport_abort_transfers(dev);
530 dev->open_count = 0; 539 dev->open_count = 0;
531 540
@@ -539,37 +548,31 @@ exit:
539/** 548/**
540 * usb_tranzport_poll 549 * usb_tranzport_poll
541 */ 550 */
542static unsigned int usb_tranzport_poll(struct file *file, poll_table *wait) 551static unsigned int usb_tranzport_poll(struct file *file, poll_table * wait)
543{ 552{
544 struct usb_tranzport *dev; 553 struct usb_tranzport *dev;
545 unsigned int mask = 0; 554 unsigned int mask = 0;
546
547 dev = file->private_data; 555 dev = file->private_data;
548
549 poll_wait(file, &dev->read_wait, wait); 556 poll_wait(file, &dev->read_wait, wait);
550 poll_wait(file, &dev->write_wait, wait); 557 poll_wait(file, &dev->write_wait, wait);
551
552 if (dev->ring_head != dev->ring_tail) 558 if (dev->ring_head != dev->ring_tail)
553 mask |= POLLIN | POLLRDNORM; 559 mask |= POLLIN | POLLRDNORM;
554 if (!dev->interrupt_out_busy) 560 if (!dev->interrupt_out_busy)
555 mask |= POLLOUT | POLLWRNORM; 561 mask |= POLLOUT | POLLWRNORM;
556
557 return mask; 562 return mask;
558} 563}
559
560/** 564/**
561 * usb_tranzport_read 565 * usb_tranzport_read
562 */ 566 */
563static ssize_t usb_tranzport_read(struct file *file, char __user *buffer, size_t count, 567
564 loff_t *ppos) 568static ssize_t usb_tranzport_read(struct file *file, char __user *buffer,
569 size_t count, loff_t *ppos)
565{ 570{
566 struct usb_tranzport *dev; 571 struct usb_tranzport *dev;
567 int retval = 0; 572 int retval = 0;
568
569#if BUFFERED_READS 573#if BUFFERED_READS
570 int c = 0; 574 int c = 0;
571#endif 575#endif
572
573#if COMPRESS_WHEEL_EVENTS 576#if COMPRESS_WHEEL_EVENTS
574 signed char oldwheel; 577 signed char oldwheel;
575 signed char newwheel; 578 signed char newwheel;
@@ -577,7 +580,7 @@ static ssize_t usb_tranzport_read(struct file *file, char __user *buffer, size_t
577 int next_tail; 580 int next_tail;
578#endif 581#endif
579 582
580/* do I have such a thing as a null event? */ 583 /* do I have such a thing as a null event? */
581 584
582 dev = file->private_data; 585 dev = file->private_data;
583 586
@@ -591,8 +594,7 @@ static ssize_t usb_tranzport_read(struct file *file, char __user *buffer, size_t
591 goto exit; 594 goto exit;
592 } 595 }
593 596
594 /* verify that the device wasn't unplugged */ 597 /* verify that the device wasn't unplugged */ if (dev->intf == NULL) {
595 if (dev->intf == NULL) {
596 retval = -ENODEV; 598 retval = -ENODEV;
597 err("No device or device unplugged %d\n", retval); 599 err("No device or device unplugged %d\n", retval);
598 goto unlock_exit; 600 goto unlock_exit;
@@ -604,104 +606,149 @@ static ssize_t usb_tranzport_read(struct file *file, char __user *buffer, size_t
604 retval = -EAGAIN; 606 retval = -EAGAIN;
605 goto unlock_exit; 607 goto unlock_exit;
606 } 608 }
607 // atomic_cmp_exchange(&dev->interrupt_in_done,0,0); 609 /* tiny race - FIXME: make atomic? */
608 dev->interrupt_in_done = 0 ; /* tiny race - FIXME: make atomic? */ 610 /* atomic_cmp_exchange(&dev->interrupt_in_done,0,0); */
609 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done); 611 dev->interrupt_in_done = 0;
610 if (retval < 0) { 612 retval = wait_event_interruptible(dev->read_wait,
613 dev->interrupt_in_done);
614 if (retval < 0)
611 goto unlock_exit; 615 goto unlock_exit;
612 }
613 } 616 }
614 617
615 dbg_info(&dev->intf->dev, "%s: copying to userspace: %02x%02x%02x%02x%02x%02x%02x%02x\n", 618 dbg_info(&dev->intf->dev,
616 __func__, (*dev->ring_buffer)[dev->ring_tail].cmd[0],(*dev->ring_buffer)[dev->ring_tail].cmd[1],(*dev->ring_buffer)[dev->ring_tail].cmd[2],(*dev->ring_buffer)[dev->ring_tail].cmd[3],(*dev->ring_buffer)[dev->ring_tail].cmd[4],(*dev->ring_buffer)[dev->ring_tail].cmd[5],(*dev->ring_buffer)[dev->ring_tail].cmd[6],(*dev->ring_buffer)[dev->ring_tail].cmd[7]); 619 "%s: copying to userspace: "
620 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
621 __func__,
622 (*dev->ring_buffer)[dev->ring_tail].cmd[0],
623 (*dev->ring_buffer)[dev->ring_tail].cmd[1],
624 (*dev->ring_buffer)[dev->ring_tail].cmd[2],
625 (*dev->ring_buffer)[dev->ring_tail].cmd[3],
626 (*dev->ring_buffer)[dev->ring_tail].cmd[4],
627 (*dev->ring_buffer)[dev->ring_tail].cmd[5],
628 (*dev->ring_buffer)[dev->ring_tail].cmd[6],
629 (*dev->ring_buffer)[dev->ring_tail].cmd[7]);
617 630
618#if BUFFERED_READS 631#if BUFFERED_READS
619 c = 0; 632 c = 0;
620 while((c < count) && (dev->ring_tail != dev->ring_head)) { 633 while ((c < count) && (dev->ring_tail != dev->ring_head)) {
621 634
622/* This started off in the lower level service routine, and I moved it here. Then my brain died. Not done yet. */
623#if COMPRESS_WHEEL_EVENTS 635#if COMPRESS_WHEEL_EVENTS
624 next_tail = (dev->ring_tail+1) % ring_buffer_size; 636 next_tail = (dev->ring_tail+1) % ring_buffer_size;
625 if(dev->compress_wheel) cancompress = 1; 637 if (dev->compress_wheel)
626 while(dev->ring_head != next_tail && cancompress == 1 ) { 638 cancompress = 1;
639 while (dev->ring_head != next_tail && cancompress == 1) {
627 newwheel = (*dev->ring_buffer)[next_tail].cmd[6]; 640 newwheel = (*dev->ring_buffer)[next_tail].cmd[6];
628 oldwheel = (*dev->ring_buffer)[dev->ring_tail].cmd[6]; 641 oldwheel = (*dev->ring_buffer)[dev->ring_tail].cmd[6];
629 // if both are wheel events, and no buttons have changes (FIXME, do I have to check?), 642 /* if both are wheel events, and
630 // and we are the same sign, we can compress +- 7F 643 no buttons have changes (FIXME, do I have to check?),
631 // FIXME: saner check for overflow! - max of +- 7F 644 and we are the same sign, we can compress +- 7F
632 // FIXME the math is wrong for going in reverse, actually, as the midi spec doesn't allow signed chars 645 */
633 646 dbg_info(&dev->intf->dev,
634 dbg_info(&dev->intf->dev, "%s: trying to compress: %02x%02x%02x%02x%02x %02x %02x %02x\n", 647 "%s: trying to compress: "
635 __func__, (*dev->ring_buffer)[dev->ring_tail].cmd[0],(*dev->ring_buffer)[dev->ring_tail].cmd[1],(*dev->ring_buffer)[dev->ring_tail].cmd[2],(*dev->ring_buffer)[dev->ring_tail].cmd[3],(*dev->ring_buffer)[dev->ring_tail].cmd[4],(*dev->ring_buffer)[dev->ring_tail].cmd[5],(*dev->ring_buffer)[dev->ring_tail].cmd[6],(*dev->ring_buffer)[dev->ring_tail].cmd[7]); 648 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
636 649 __func__,
637 650 (*dev->ring_buffer)[dev->ring_tail].cmd[0],
638 if(((*dev->ring_buffer)[dev->ring_tail].cmd[6] != 0 && 651 (*dev->ring_buffer)[dev->ring_tail].cmd[1],
639 (*dev->ring_buffer)[next_tail].cmd[6] != 0 ) && 652 (*dev->ring_buffer)[dev->ring_tail].cmd[2],
653 (*dev->ring_buffer)[dev->ring_tail].cmd[3],
654 (*dev->ring_buffer)[dev->ring_tail].cmd[4],
655 (*dev->ring_buffer)[dev->ring_tail].cmd[5],
656 (*dev->ring_buffer)[dev->ring_tail].cmd[6],
657 (*dev->ring_buffer)[dev->ring_tail].cmd[7]);
658
659 if (((*dev->ring_buffer)[dev->ring_tail].cmd[6] != 0 &&
660 (*dev->ring_buffer)[next_tail].cmd[6] != 0) &&
640 ((newwheel > 0 && oldwheel > 0) || 661 ((newwheel > 0 && oldwheel > 0) ||
641 (newwheel < 0 && oldwheel < 0)) && 662 (newwheel < 0 && oldwheel < 0)) &&
642 ((*dev->ring_buffer)[dev->ring_tail].cmd[2] == (*dev->ring_buffer)[next_tail].cmd[2]) && 663 ((*dev->ring_buffer)[dev->ring_tail].cmd[2] ==
643 ((*dev->ring_buffer)[dev->ring_tail].cmd[3] == (*dev->ring_buffer)[next_tail].cmd[3]) && 664 (*dev->ring_buffer)[next_tail].cmd[2]) &&
644 ((*dev->ring_buffer)[dev->ring_tail].cmd[4] == (*dev->ring_buffer)[next_tail].cmd[4]) && 665 ((*dev->ring_buffer)[dev->ring_tail].cmd[3] ==
645 ((*dev->ring_buffer)[dev->ring_tail].cmd[5] == (*dev->ring_buffer)[next_tail].cmd[5])) 666 (*dev->ring_buffer)[next_tail].cmd[3]) &&
646 { 667 ((*dev->ring_buffer)[dev->ring_tail].cmd[4] ==
647 dbg_info(&dev->intf->dev, "%s: should compress: %02x%02x%02x%02x%02x%02x%02x%02x\n", 668 (*dev->ring_buffer)[next_tail].cmd[4]) &&
648 __func__, (*dev->ring_buffer)[dev->ring_tail].cmd[0],(*dev->ring_buffer)[dev->ring_tail].cmd[1],(*dev->ring_buffer)[dev->ring_tail].cmd[2],(*dev->ring_buffer)[dev->ring_tail].cmd[3],(*dev->ring_buffer)[dev->ring_tail].cmd[4],(*dev->ring_buffer)[dev->ring_tail].cmd[5],(*dev->ring_buffer)[dev->ring_tail].cmd[6],(*dev->ring_buffer)[dev->ring_tail].cmd[7]); 669 ((*dev->ring_buffer)[dev->ring_tail].cmd[5] ==
649 670 (*dev->ring_buffer)[next_tail].cmd[5])) {
671 dbg_info(&dev->intf->dev,
672 "%s: should compress: "
673 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
674 __func__,
675 (*dev->ring_buffer)[dev->ring_tail].
676 cmd[0],
677 (*dev->ring_buffer)[dev->ring_tail].
678 cmd[1],
679 (*dev->ring_buffer)[dev->ring_tail].
680 cmd[2],
681 (*dev->ring_buffer)[dev->ring_tail].
682 cmd[3],
683 (*dev->ring_buffer)[dev->ring_tail].
684 cmd[4],
685 (*dev->ring_buffer)[dev->ring_tail].
686 cmd[5],
687 (*dev->ring_buffer)[dev->ring_tail].
688 cmd[6],
689 (*dev->ring_buffer)[dev->ring_tail].
690 cmd[7]);
650 newwheel += oldwheel; 691 newwheel += oldwheel;
651 if(oldwheel > 0 && !(newwheel > 0)) { 692 if (oldwheel > 0 && !(newwheel > 0)) {
652 newwheel = 0x7f; 693 newwheel = 0x7f;
653 cancompress = 0; 694 cancompress = 0;
654 } 695 }
655 if(oldwheel < 0 && !(newwheel < 0)) { 696 if (oldwheel < 0 && !(newwheel < 0)) {
656 newwheel = 0x80; 697 newwheel = 0x80;
657 cancompress = 0; 698 cancompress = 0;
658 } 699 }
659 700
660 (*dev->ring_buffer)[next_tail].cmd[6] = newwheel; 701 (*dev->ring_buffer)[next_tail].cmd[6] =
702 newwheel;
661 dev->ring_tail = next_tail; 703 dev->ring_tail = next_tail;
662 next_tail = (dev->ring_tail+1) % ring_buffer_size; 704 next_tail =
705 (dev->ring_tail + 1) % ring_buffer_size;
663 } else { 706 } else {
664 cancompress = 0; 707 cancompress = 0;
665 } 708 }
666 } 709 }
667#endif /* COMPRESS_WHEEL_EVENTS */ 710#endif /* COMPRESS_WHEEL_EVENTS */
668 711 if (copy_to_user(
669 if (copy_to_user(&buffer[c], &(*dev->ring_buffer)[dev->ring_tail], 8)) { 712 &buffer[c],
713 &(*dev->ring_buffer)[dev->ring_tail], 8)) {
670 retval = -EFAULT; 714 retval = -EFAULT;
671 goto unlock_exit; 715 goto unlock_exit;
672 } 716 }
673 717 dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
674 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size; 718 c += 8;
675 c+=8; 719 dbg_info(&dev->intf->dev,
676 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n", __func__,dev->ring_head,dev->ring_tail); 720 "%s: head, tail are %x, %x\n",
677 } 721 __func__, dev->ring_head, dev->ring_tail);
678 retval = c; 722 }
723 retval = c;
679 724
680#else 725#else
681 if (copy_to_user(buffer, &(*dev->ring_buffer)[dev->ring_tail], 8)) { 726/* if (copy_to_user(buffer, &(*dev->ring_buffer)[dev->ring_tail], 8)) { */
682 retval = -EFAULT; 727 retval = -EFAULT;
683 goto unlock_exit; 728 goto unlock_exit;
684 } 729}
685 730
686 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size; 731dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
687 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n", __func__,dev->ring_head,dev->ring_tail); 732dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n",
733 __func__, dev->ring_head, dev->ring_tail);
688 734
689 retval = 8; 735retval = 8;
690#endif /* BUFFERED_READS */ 736#endif /* BUFFERED_READS */
691 737
692unlock_exit: 738unlock_exit:
693 /* unlock the device */ 739/* unlock the device */
694 up(&dev->sem); 740up(&dev->sem);
695 741
696exit: 742exit:
697 return retval; 743return retval;
698} 744}
699 745
700/** 746/**
701 * usb_tranzport_write 747 * usb_tranzport_write
702 */ 748 */
703static ssize_t usb_tranzport_write(struct file *file, const char __user *buffer, 749static ssize_t usb_tranzport_write(struct file *file,
704 size_t count, loff_t *ppos) 750 const char __user *buffer, size_t count,
751 loff_t *ppos)
705{ 752{
706 struct usb_tranzport *dev; 753 struct usb_tranzport *dev;
707 size_t bytes_to_write; 754 size_t bytes_to_write;
@@ -718,7 +765,6 @@ static ssize_t usb_tranzport_write(struct file *file, const char __user *buffer,
718 retval = -ERESTARTSYS; 765 retval = -ERESTARTSYS;
719 goto exit; 766 goto exit;
720 } 767 }
721
722 /* verify that the device wasn't unplugged */ 768 /* verify that the device wasn't unplugged */
723 if (dev->intf == NULL) { 769 if (dev->intf == NULL) {
724 retval = -ENODEV; 770 retval = -ENODEV;
@@ -732,18 +778,24 @@ static ssize_t usb_tranzport_write(struct file *file, const char __user *buffer,
732 retval = -EAGAIN; 778 retval = -EAGAIN;
733 goto unlock_exit; 779 goto unlock_exit;
734 } 780 }
735 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy); 781 retval = wait_event_interruptible(dev->write_wait,
736 if (retval < 0) { 782 !dev->interrupt_out_busy);
783 if (retval < 0)
737 goto unlock_exit; 784 goto unlock_exit;
738 }
739 } 785 }
740 786
741 /* write the data into interrupt_out_buffer from userspace */ 787 /* write the data into interrupt_out_buffer from userspace */
742 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size); 788 bytes_to_write = min(count,
789 write_buffer_size *
790 dev->interrupt_out_endpoint_size);
743 if (bytes_to_write < count) 791 if (bytes_to_write < count)
744 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write); 792 dev_warn(&dev->intf->dev,
793 "Write buffer overflow, %zd bytes dropped\n",
794 count - bytes_to_write);
745 795
746 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __func__, count, bytes_to_write); 796 dbg_info(&dev->intf->dev,
797 "%s: count = %zd, bytes_to_write = %zd\n", __func__,
798 count, bytes_to_write);
747 799
748 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) { 800 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
749 retval = -EFAULT; 801 retval = -EFAULT;
@@ -757,14 +809,13 @@ static ssize_t usb_tranzport_write(struct file *file, const char __user *buffer,
757 809
758 /* send off the urb */ 810 /* send off the urb */
759 usb_fill_int_urb(dev->interrupt_out_urb, 811 usb_fill_int_urb(dev->interrupt_out_urb,
760 interface_to_usbdev(dev->intf), 812 interface_to_usbdev(dev->intf),
761 usb_sndintpipe(interface_to_usbdev(dev->intf), 813 usb_sndintpipe(interface_to_usbdev(dev->intf),
762 dev->interrupt_out_endpoint->bEndpointAddress), 814 dev->interrupt_out_endpoint->
763 dev->interrupt_out_buffer, 815 bEndpointAddress),
764 bytes_to_write, 816 dev->interrupt_out_buffer, bytes_to_write,
765 usb_tranzport_interrupt_out_callback, 817 usb_tranzport_interrupt_out_callback, dev,
766 dev, 818 dev->interrupt_out_interval);
767 dev->interrupt_out_interval);
768 819
769 dev->interrupt_out_busy = 1; 820 dev->interrupt_out_busy = 1;
770 wmb(); 821 wmb();
@@ -787,12 +838,12 @@ exit:
787 838
788/* file operations needed when we register this driver */ 839/* file operations needed when we register this driver */
789static const struct file_operations usb_tranzport_fops = { 840static const struct file_operations usb_tranzport_fops = {
790 .owner = THIS_MODULE, 841 .owner = THIS_MODULE,
791 .read = usb_tranzport_read, 842 .read = usb_tranzport_read,
792 .write = usb_tranzport_write, 843 .write = usb_tranzport_write,
793 .open = usb_tranzport_open, 844 .open = usb_tranzport_open,
794 .release = usb_tranzport_release, 845 .release = usb_tranzport_release,
795 .poll = usb_tranzport_poll, 846 .poll = usb_tranzport_poll,
796}; 847};
797 848
798/* 849/*
@@ -800,20 +851,19 @@ static const struct file_operations usb_tranzport_fops = {
800 * and to have the device registered with the driver core 851 * and to have the device registered with the driver core
801 */ 852 */
802static struct usb_class_driver usb_tranzport_class = { 853static struct usb_class_driver usb_tranzport_class = {
803 .name = "tranzport%d", 854 .name = "tranzport%d",
804 .fops = &usb_tranzport_fops, 855 .fops = &usb_tranzport_fops,
805 .minor_base = USB_TRANZPORT_MINOR_BASE, 856 .minor_base = USB_TRANZPORT_MINOR_BASE,
806}; 857};
807 858
808
809/** 859/**
810 * usb_tranzport_probe 860 * usb_tranzport_probe
811 * 861 *
812 * Called by the usb core when a new device is connected that it thinks 862 * Called by the usb core when a new device is connected that it thinks
813 * this driver might be interested in. 863 * this driver might be interested in.
814 */ 864 */
815static int usb_tranzport_probe(struct usb_interface *intf, const struct usb_device_id *id) 865static int usb_tranzport_probe(struct usb_interface *intf,
816{ 866 const struct usb_device_id *id) {
817 struct usb_device *udev = interface_to_usbdev(intf); 867 struct usb_device *udev = interface_to_usbdev(intf);
818 struct usb_tranzport *dev = NULL; 868 struct usb_tranzport *dev = NULL;
819 struct usb_host_interface *iface_desc; 869 struct usb_host_interface *iface_desc;
@@ -824,7 +874,7 @@ static int usb_tranzport_probe(struct usb_interface *intf, const struct usb_devi
824 874
825 /* allocate memory for our device state and intialize it */ 875 /* allocate memory for our device state and intialize it */
826 876
827 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 877 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
828 if (dev == NULL) { 878 if (dev == NULL) {
829 dev_err(&intf->dev, "Out of memory\n"); 879 dev_err(&intf->dev, "Out of memory\n");
830 goto exit; 880 goto exit;
@@ -851,25 +901,33 @@ static int usb_tranzport_probe(struct usb_interface *intf, const struct usb_devi
851 goto error; 901 goto error;
852 } 902 }
853 if (dev->interrupt_out_endpoint == NULL) 903 if (dev->interrupt_out_endpoint == NULL)
854 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n"); 904 dev_warn(&intf->dev,
855 905 "Interrupt out endpoint not found"
906 "(using control endpoint instead)\n");
856 907
857 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize); 908 dev->interrupt_in_endpoint_size =
909 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
858 910
859 if (dev->interrupt_in_endpoint_size != 8) 911 if (dev->interrupt_in_endpoint_size != 8)
860 dev_warn(&intf->dev, "Interrupt in endpoint size is not 8!\n"); 912 dev_warn(&intf->dev, "Interrupt in endpoint size is not 8!\n");
861 913
862 if(ring_buffer_size == 0) { ring_buffer_size = RING_BUFFER_SIZE; } 914 if (ring_buffer_size == 0)
863 true_size = min(ring_buffer_size,RING_BUFFER_SIZE); 915 ring_buffer_size = RING_BUFFER_SIZE;
864 /* FIXME - there are more usb_alloc routines for dma correctness. Needed? */ 916 true_size = min(ring_buffer_size, RING_BUFFER_SIZE);
865 917
866 dev->ring_buffer = kmalloc((true_size*sizeof(struct tranzport_cmd))+8, GFP_KERNEL); 918 /* FIXME - there are more usb_alloc routines for dma correctness.
919 Needed? */
920
921 dev->ring_buffer =
922 kmalloc((true_size * sizeof(struct tranzport_cmd)) + 8, GFP_KERNEL);
867 923
868 if (!dev->ring_buffer) { 924 if (!dev->ring_buffer) {
869 dev_err(&intf->dev, "Couldn't allocate ring_buffer of size %d\n",true_size); 925 dev_err(&intf->dev,
926 "Couldn't allocate ring_buffer size %d\n", true_size);
870 goto error; 927 goto error;
871 } 928 }
872 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); 929 dev->interrupt_in_buffer =
930 kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
873 if (!dev->interrupt_in_buffer) { 931 if (!dev->interrupt_in_buffer) {
874 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n"); 932 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
875 goto error; 933 goto error;
@@ -879,13 +937,18 @@ static int usb_tranzport_probe(struct usb_interface *intf, const struct usb_devi
879 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); 937 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
880 goto error; 938 goto error;
881 } 939 }
882 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) : 940 dev->interrupt_out_endpoint_size =
883 udev->descriptor.bMaxPacketSize0; 941 dev->interrupt_out_endpoint ?
884 942 le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) :
885 if (dev->interrupt_out_endpoint_size !=8) 943 udev->descriptor.bMaxPacketSize0;
886 dev_warn(&intf->dev, "Interrupt out endpoint size is not 8!)\n"); 944
887 945 if (dev->interrupt_out_endpoint_size != 8)
888 dev->interrupt_out_buffer = kmalloc(write_buffer_size*dev->interrupt_out_endpoint_size, GFP_KERNEL); 946 dev_warn(&intf->dev,
947 "Interrupt out endpoint size is not 8!)\n");
948
949 dev->interrupt_out_buffer =
950 kmalloc(write_buffer_size * dev->interrupt_out_endpoint_size,
951 GFP_KERNEL);
889 if (!dev->interrupt_out_buffer) { 952 if (!dev->interrupt_out_buffer) {
890 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n"); 953 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
891 goto error; 954 goto error;
@@ -895,9 +958,18 @@ static int usb_tranzport_probe(struct usb_interface *intf, const struct usb_devi
895 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n"); 958 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
896 goto error; 959 goto error;
897 } 960 }
898 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; 961 dev->interrupt_in_interval =
899 if (dev->interrupt_out_endpoint) 962 min_interrupt_in_interval >
900 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; 963 dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval
964 : dev->interrupt_in_endpoint->bInterval;
965
966 if (dev->interrupt_out_endpoint) {
967 dev->interrupt_out_interval =
968 min_interrupt_out_interval >
969 dev->interrupt_out_endpoint->bInterval ?
970 min_interrupt_out_interval :
971 dev->interrupt_out_endpoint->bInterval;
972 }
901 973
902 /* we can register the device now, as it is ready */ 974 /* we can register the device now, as it is ready */
903 usb_set_intfdata(intf, dev); 975 usb_set_intfdata(intf, dev);
@@ -905,35 +977,63 @@ static int usb_tranzport_probe(struct usb_interface *intf, const struct usb_devi
905 retval = usb_register_dev(intf, &usb_tranzport_class); 977 retval = usb_register_dev(intf, &usb_tranzport_class);
906 if (retval) { 978 if (retval) {
907 /* something prevented us from registering this driver */ 979 /* something prevented us from registering this driver */
908 dev_err(&intf->dev, "Not able to get a minor for this device.\n"); 980 dev_err(&intf->dev,
981 "Not able to get a minor for this device.\n");
909 usb_set_intfdata(intf, NULL); 982 usb_set_intfdata(intf, NULL);
910 goto error; 983 goto error;
911 } 984 }
912 985
913 if((retval = device_create_file(&intf->dev, &dev_attr_LightRecord))) goto error; 986 retval = device_create_file(&intf->dev, &dev_attr_LightRecord);
914 if((retval = device_create_file(&intf->dev, &dev_attr_LightTrackrec))) goto error; 987 if (retval)
915 if((retval = device_create_file(&intf->dev, &dev_attr_LightTrackmute))) goto error; 988 goto error;
916 if((retval = device_create_file(&intf->dev, &dev_attr_LightTracksolo))) goto error; 989 retval = device_create_file(&intf->dev, &dev_attr_LightTrackrec);
917 if((retval = device_create_file(&intf->dev, &dev_attr_LightAnysolo))) goto error; 990 if (retval)
918 if((retval = device_create_file(&intf->dev, &dev_attr_LightLoop))) goto error; 991 goto error;
919 if((retval = device_create_file(&intf->dev, &dev_attr_LightPunch))) goto error; 992 retval = device_create_file(&intf->dev, &dev_attr_LightTrackmute);
920 if((retval = device_create_file(&intf->dev, &dev_attr_wheel))) goto error; 993 if (retval)
921 if((retval = device_create_file(&intf->dev, &dev_attr_event))) goto error; 994 goto error;
922 if((retval = device_create_file(&intf->dev, &dev_attr_dump_state))) goto error; 995 retval = device_create_file(&intf->dev, &dev_attr_LightTracksolo);
923 if((retval = device_create_file(&intf->dev, &dev_attr_compress_wheel))) goto error; 996 if (retval)
924 if((retval = device_create_file(&intf->dev, &dev_attr_enable))) goto error; 997 goto error;
925 if((retval = device_create_file(&intf->dev, &dev_attr_offline))) goto error; 998 retval = device_create_file(&intf->dev, &dev_attr_LightAnysolo);
999 if (retval)
1000 goto error;
1001 retval = device_create_file(&intf->dev, &dev_attr_LightLoop);
1002 if (retval)
1003 goto error;
1004 retval = device_create_file(&intf->dev, &dev_attr_LightPunch);
1005 if (retval)
1006 goto error;
1007 retval = device_create_file(&intf->dev, &dev_attr_wheel);
1008 if (retval)
1009 goto error;
1010 retval = device_create_file(&intf->dev, &dev_attr_event);
1011 if (retval)
1012 goto error;
1013 retval = device_create_file(&intf->dev, &dev_attr_dump_state);
1014 if (retval)
1015 goto error;
1016 retval = device_create_file(&intf->dev, &dev_attr_compress_wheel);
1017 if (retval)
1018 goto error;
1019 retval = device_create_file(&intf->dev, &dev_attr_enable);
1020 if (retval)
1021 goto error;
1022 retval = device_create_file(&intf->dev, &dev_attr_offline);
1023 if (retval)
1024 goto error;
926 1025
927 /* let the user know what node this device is now attached to */ 1026 /* let the user know what node this device is now attached to */
928 dev_info(&intf->dev, "Tranzport Device #%d now attached to major %d minor %d\n", 1027 dev_info(&intf->dev,
929 (intf->minor - USB_TRANZPORT_MINOR_BASE), USB_MAJOR, intf->minor); 1028 "Tranzport Device #%d now attached to major %d minor %d\n",
1029 (intf->minor - USB_TRANZPORT_MINOR_BASE), USB_MAJOR,
1030 intf->minor);
930 1031
931exit: 1032exit:
932 return retval; 1033 return retval;
933 1034
934error: 1035error:
935 usb_tranzport_delete(dev); 1036 usb_tranzport_delete(dev);
936
937 return retval; 1037 return retval;
938} 1038}
939 1039
@@ -966,15 +1066,15 @@ static void usb_tranzport_disconnect(struct usb_interface *intf)
966 mutex_unlock(&disconnect_mutex); 1066 mutex_unlock(&disconnect_mutex);
967 1067
968 dev_info(&intf->dev, "Tranzport Surface #%d now disconnected\n", 1068 dev_info(&intf->dev, "Tranzport Surface #%d now disconnected\n",
969 (minor - USB_TRANZPORT_MINOR_BASE)); 1069 (minor - USB_TRANZPORT_MINOR_BASE));
970} 1070}
971 1071
972/* usb specific object needed to register this driver with the usb subsystem */ 1072/* usb specific object needed to register this driver with the usb subsystem */
973static struct usb_driver usb_tranzport_driver = { 1073static struct usb_driver usb_tranzport_driver = {
974 .name = "tranzport", 1074 .name = "tranzport",
975 .probe = usb_tranzport_probe, 1075 .probe = usb_tranzport_probe,
976 .disconnect = usb_tranzport_disconnect, 1076 .disconnect = usb_tranzport_disconnect,
977 .id_table = usb_tranzport_table, 1077 .id_table = usb_tranzport_table,
978}; 1078};
979 1079
980/** 1080/**
@@ -987,14 +1087,14 @@ static int __init usb_tranzport_init(void)
987 /* register this driver with the USB subsystem */ 1087 /* register this driver with the USB subsystem */
988 retval = usb_register(&usb_tranzport_driver); 1088 retval = usb_register(&usb_tranzport_driver);
989 if (retval) 1089 if (retval)
990 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval); 1090 err("usb_register failed for the " __FILE__
991 1091 " driver. Error number %d\n", retval);
992 return retval; 1092 return retval;
993} 1093}
994
995/** 1094/**
996 * usb_tranzport_exit 1095 * usb_tranzport_exit
997 */ 1096 */
1097
998static void __exit usb_tranzport_exit(void) 1098static void __exit usb_tranzport_exit(void)
999{ 1099{
1000 /* deregister this driver with the USB subsystem */ 1100 /* deregister this driver with the USB subsystem */
@@ -1003,4 +1103,3 @@ static void __exit usb_tranzport_exit(void)
1003 1103
1004module_init(usb_tranzport_init); 1104module_init(usb_tranzport_init);
1005module_exit(usb_tranzport_exit); 1105module_exit(usb_tranzport_exit);
1006