aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/frontier
diff options
context:
space:
mode:
authorDavid Täht <d@teklibre.com>2009-01-20 09:33:21 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-04-03 17:53:31 -0400
commitf6a0ccadd1ab24818897fcbe039a248fee3cbd34 (patch)
treef554a4668af13408f19198774466f0c483cb2d16 /drivers/staging/frontier
parent7c68d6b7171aa2f3d0c68b9ff54a2e1f0f0e228f (diff)
Staging: frontier: Make checkpatch.pl much happier with alphatrack driver
Signed-off-by: David Täht <d@teklibre.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/frontier')
-rw-r--r--drivers/staging/frontier/alphatrack.c381
1 files changed, 213 insertions, 168 deletions
diff --git a/drivers/staging/frontier/alphatrack.c b/drivers/staging/frontier/alphatrack.c
index 6136e3f8762..97d28ce45f1 100644
--- a/drivers/staging/frontier/alphatrack.c
+++ b/drivers/staging/frontier/alphatrack.c
@@ -41,19 +41,13 @@
41#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/version.h> 42#include <linux/version.h>
43 43
44#include <asm/uaccess.h> 44#include <linux/uaccess.h>
45#include <linux/input.h> 45#include <linux/input.h>
46#include <linux/usb.h> 46#include <linux/usb.h>
47#include <linux/poll.h> 47#include <linux/poll.h>
48 48
49#include "surface_sysfs.h" 49#include "surface_sysfs.h"
50 50
51/* make this work on older kernel versions */
52
53#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
54#include "frontier_compat.h"
55#endif /* older kernel versions */
56
57#include "alphatrack.h" 51#include "alphatrack.h"
58 52
59#define VENDOR_ID 0x165b 53#define VENDOR_ID 0x165b
@@ -62,19 +56,18 @@
62#ifdef CONFIG_USB_DYNAMIC_MINORS 56#ifdef CONFIG_USB_DYNAMIC_MINORS
63#define USB_ALPHATRACK_MINOR_BASE 0 57#define USB_ALPHATRACK_MINOR_BASE 0
64#else 58#else
65// FIXME 176 - is another driver's minor - apply for that 59/* FIXME 176 - is another driver's minor - apply for that */
66// #define USB_ALPHATRACK_MINOR_BASE 177
67#define USB_ALPHATRACK_MINOR_BASE 176 60#define USB_ALPHATRACK_MINOR_BASE 176
68#endif 61#endif
69 62
70/* table of devices that work with this driver */ 63/* table of devices that work with this driver */
71static struct usb_device_id usb_alphatrack_table [] = { 64static struct usb_device_id usb_alphatrack_table[] = {
72 { USB_DEVICE(VENDOR_ID, PRODUCT_ID) }, 65 {USB_DEVICE(VENDOR_ID, PRODUCT_ID)},
73 { } /* Terminating entry */ 66 {} /* Terminating entry */
74}; 67};
75 68
76MODULE_DEVICE_TABLE(usb, usb_alphatrack_table); 69MODULE_DEVICE_TABLE(usb, usb_alphatrack_table);
77MODULE_VERSION("0.40"); 70MODULE_VERSION("0.41");
78MODULE_AUTHOR("Mike Taht <m@taht.net>"); 71MODULE_AUTHOR("Mike Taht <m@taht.net>");
79MODULE_DESCRIPTION("Alphatrack USB Driver"); 72MODULE_DESCRIPTION("Alphatrack USB Driver");
80MODULE_LICENSE("GPL"); 73MODULE_LICENSE("GPL");
@@ -93,18 +86,18 @@ MODULE_SUPPORTED_DEVICE("Frontier Designs Alphatrack Control Surface");
93#define ALPHATRACK_USB_TIMEOUT 10 86#define ALPHATRACK_USB_TIMEOUT 10
94#define OUTPUT_CMD_SIZE 8 87#define OUTPUT_CMD_SIZE 8
95#define INPUT_CMD_SIZE 12 88#define INPUT_CMD_SIZE 12
89#define ALPHATRACK_DEBUG 0
96 90
97 91static int debug = ALPHATRACK_DEBUG;
98static int debug = 0;
99 92
100/* Use our own dbg macro */ 93/* Use our own dbg macro */
101#define dbg_info(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) 94#define dbg_info(dev, format, arg...) do \
95 { if (debug) dev_info(dev , format , ## arg); } while (0)
102 96
103#define alphatrack_ocmd_info(dev, cmd, format, arg...) 97#define alphatrack_ocmd_info(dev, cmd, format, arg...)
104 98
105#define alphatrack_icmd_info(dev, cmd, format, arg...) 99#define alphatrack_icmd_info(dev, cmd, format, arg...)
106 100
107
108/* Module parameters */ 101/* Module parameters */
109 102
110module_param(debug, int, S_IRUGO | S_IWUSR); 103module_param(debug, int, S_IRUGO | S_IWUSR);
@@ -116,14 +109,14 @@ MODULE_PARM_DESC(debug, "Debug enabled or not");
116 109
117static int ring_buffer_size = RING_BUFFER_SIZE; 110static int ring_buffer_size = RING_BUFFER_SIZE;
118 111
119module_param(ring_buffer_size, int, S_IRUGO); 112module_param(ring_buffer_size, int, S_IRUGO);
120MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size"); 113MODULE_PARM_DESC(ring_buffer_size, "Read ring buffer size");
121 114
122/* The write_buffer can one day contain more than one interrupt out transfer. 115/* The write_buffer can one day contain more than one interrupt out transfer.
123 */ 116 */
124 117
125static int write_buffer_size = WRITE_BUFFER_SIZE; 118static int write_buffer_size = WRITE_BUFFER_SIZE;
126module_param(write_buffer_size, int, S_IRUGO); 119module_param(write_buffer_size, int, S_IRUGO);
127MODULE_PARM_DESC(write_buffer_size, "Write buffer size"); 120MODULE_PARM_DESC(write_buffer_size, "Write buffer size");
128 121
129/* 122/*
@@ -133,55 +126,56 @@ MODULE_PARM_DESC(write_buffer_size, "Write buffer size");
133 126
134static int min_interrupt_in_interval = ALPHATRACK_USB_TIMEOUT; 127static int min_interrupt_in_interval = ALPHATRACK_USB_TIMEOUT;
135module_param(min_interrupt_in_interval, int, 0); 128module_param(min_interrupt_in_interval, int, 0);
136MODULE_PARM_DESC(min_interrupt_in_interval, "Minimum interrupt in interval in ms"); 129MODULE_PARM_DESC(min_interrupt_in_interval,
130 "Minimum interrupt in interval in ms");
137 131
138static int min_interrupt_out_interval = ALPHATRACK_USB_TIMEOUT; 132static int min_interrupt_out_interval = ALPHATRACK_USB_TIMEOUT;
139module_param(min_interrupt_out_interval, int, 0); 133module_param(min_interrupt_out_interval, int, 0);
140MODULE_PARM_DESC(min_interrupt_out_interval, "Minimum interrupt out interval in ms"); 134MODULE_PARM_DESC(min_interrupt_out_interval,
141 135 "Minimum interrupt out interval in ms");
142
143 136
144/* Structure to hold all of our device specific stuff */ 137/* Structure to hold all of our device specific stuff */
145 138
146struct usb_alphatrack { 139struct usb_alphatrack {
147 struct semaphore sem; /* locks this structure */ 140 struct semaphore sem; /* locks this structure */
148 struct usb_interface* intf; /* save off the usb interface pointer */ 141 struct usb_interface *intf; /* save off the usb interface pointer */
149 int open_count; /* number of times this port has been opened */ 142 int open_count; /* number of times this port has been opened */
150 143
151 struct alphatrack_icmd (*ring_buffer)[RING_BUFFER_SIZE]; /* just make c happy */ 144 /* make gcc happy */
152 struct alphatrack_ocmd (*write_buffer)[WRITE_BUFFER_SIZE]; /* just make c happy */ 145 struct alphatrack_icmd (*ring_buffer)[RING_BUFFER_SIZE];
153 unsigned int ring_head; 146 struct alphatrack_ocmd (*write_buffer)[WRITE_BUFFER_SIZE];
154 unsigned int ring_tail; 147 unsigned int ring_head;
155 148 unsigned int ring_tail;
156 wait_queue_head_t read_wait; 149
157 wait_queue_head_t write_wait; 150 wait_queue_head_t read_wait;
158 151 wait_queue_head_t write_wait;
159 unsigned char* interrupt_in_buffer; 152
160 unsigned char* oldi_buffer; 153 unsigned char *interrupt_in_buffer;
161 struct usb_endpoint_descriptor* interrupt_in_endpoint; 154 unsigned char *oldi_buffer;
162 struct urb* interrupt_in_urb; 155 struct usb_endpoint_descriptor *interrupt_in_endpoint;
163 int interrupt_in_interval; 156 struct urb *interrupt_in_urb;
164 size_t interrupt_in_endpoint_size; 157 int interrupt_in_interval;
165 int interrupt_in_running; 158 size_t interrupt_in_endpoint_size;
166 int interrupt_in_done; 159 int interrupt_in_running;
167 160 int interrupt_in_done;
168 char* interrupt_out_buffer; 161
169 struct usb_endpoint_descriptor* interrupt_out_endpoint; 162 char *interrupt_out_buffer;
170 struct urb* interrupt_out_urb; 163 struct usb_endpoint_descriptor *interrupt_out_endpoint;
171 int interrupt_out_interval; 164 struct urb *interrupt_out_urb;
172 size_t interrupt_out_endpoint_size; 165 int interrupt_out_interval;
173 int interrupt_out_busy; 166 size_t interrupt_out_endpoint_size;
167 int interrupt_out_busy;
174 168
175 atomic_t writes_pending; 169 atomic_t writes_pending;
176 int event; /* alternate interface to events */ 170 int event; /* alternate interface to events */
177 int fader; /* 10 bits */ 171 int fader; /* 10 bits */
178 int lights; /* 23 bits */ 172 int lights; /* 23 bits */
179 unsigned char dump_state; /* 0 if disabled 1 if enabled */ 173 unsigned char dump_state; /* 0 if disabled 1 if enabled */
180 unsigned char enable; /* 0 if disabled 1 if enabled */ 174 unsigned char enable; /* 0 if disabled 1 if enabled */
181 unsigned char offline; /* if the device is out of range or asleep */ 175 unsigned char offline; /* if the device is out of range or asleep */
182 unsigned char verbose; /* be verbose in error reporting */ 176 unsigned char verbose; /* be verbose in error reporting */
183 unsigned char last_cmd[OUTPUT_CMD_SIZE]; 177 unsigned char last_cmd[OUTPUT_CMD_SIZE];
184 unsigned char screen[32]; 178 unsigned char screen[32];
185}; 179};
186 180
187/* prevent races between open() and disconnect() */ 181/* prevent races between open() and disconnect() */
@@ -219,7 +213,7 @@ static void usb_alphatrack_delete(struct usb_alphatrack *dev)
219 kfree(dev->ring_buffer); 213 kfree(dev->ring_buffer);
220 kfree(dev->interrupt_in_buffer); 214 kfree(dev->interrupt_in_buffer);
221 kfree(dev->interrupt_out_buffer); 215 kfree(dev->interrupt_out_buffer);
222 kfree(dev); // fixme oldi_buffer 216 kfree(dev); /* fixme oldi_buffer */
223} 217}
224 218
225/** 219/**
@@ -234,39 +228,52 @@ static void usb_alphatrack_interrupt_in_callback(struct urb *urb)
234 228
235 if (urb->status) { 229 if (urb->status) {
236 if (urb->status == -ENOENT || 230 if (urb->status == -ENOENT ||
237 urb->status == -ECONNRESET || 231 urb->status == -ECONNRESET || urb->status == -ESHUTDOWN) {
238 urb->status == -ESHUTDOWN) {
239 goto exit; 232 goto exit;
240 } else { 233 } else {
241 dbg_info(&dev->intf->dev, "%s: nonzero status received: %d\n", 234 dbg_info(&dev->intf->dev,
242 __func__, urb->status); 235 "%s: nonzero status received: %d\n", __func__,
243 goto resubmit; /* maybe we can recover */ 236 urb->status);
237 goto resubmit; /* maybe we can recover */
244 } 238 }
245 } 239 }
246 240
247 if (urb->actual_length != INPUT_CMD_SIZE) { 241 if (urb->actual_length != INPUT_CMD_SIZE) {
248 dev_warn(&dev->intf->dev, 242 dev_warn(&dev->intf->dev,
249 "Urb length was %d bytes!! Do something intelligent \n", urb->actual_length); 243 "Urb length was %d bytes!!"
244 "Do something intelligent \n", urb->actual_length);
250 } else { 245 } else {
251 alphatrack_ocmd_info(&dev->intf->dev,&(*dev->ring_buffer)[dev->ring_tail].cmd,"%s", "bla"); 246 alphatrack_ocmd_info(&dev->intf->dev,
252 if(memcmp(dev->interrupt_in_buffer,dev->oldi_buffer,INPUT_CMD_SIZE)==0) { 247 &(*dev->ring_buffer)[dev->ring_tail].cmd,
253 goto resubmit; 248 "%s", "bla");
249 if (memcmp
250 (dev->interrupt_in_buffer, dev->oldi_buffer,
251 INPUT_CMD_SIZE) == 0) {
252 goto resubmit;
254 } 253 }
255 memcpy(dev->oldi_buffer,dev->interrupt_in_buffer,INPUT_CMD_SIZE); 254 memcpy(dev->oldi_buffer, dev->interrupt_in_buffer,
255 INPUT_CMD_SIZE);
256 256
257#if SUPPRESS_EXTRA_OFFLINE_EVENTS 257#if SUPPRESS_EXTRA_OFFLINE_EVENTS
258 if(dev->offline == 2 && dev->interrupt_in_buffer[1] == 0xff) { goto resubmit; } 258 if (dev->offline == 2 && dev->interrupt_in_buffer[1] == 0xff)
259 if(dev->offline == 1 && dev->interrupt_in_buffer[1] == 0xff) { dev->offline = 2; goto resubmit; } 259 goto resubmit;
260 if (dev->offline == 1 && dev->interrupt_in_buffer[1] == 0xff) {
261 dev->offline = 2;
262 goto resubmit;
263 }
260/* Always pass one offline event up the stack */ 264/* Always pass one offline event up the stack */
261 if(dev->offline > 0 && dev->interrupt_in_buffer[1] != 0xff) { dev->offline = 0; } 265 if (dev->offline > 0 && dev->interrupt_in_buffer[1] != 0xff)
262 if(dev->offline == 0 && dev->interrupt_in_buffer[1] == 0xff) { dev->offline = 1; } 266 dev->offline = 0;
267 if (dev->offline == 0 && dev->interrupt_in_buffer[1] == 0xff)
268 dev->offline = 1;
263#endif 269#endif
264 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n", __func__,dev->ring_head,dev->ring_tail); 270 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n",
265 next_ring_head = (dev->ring_head+1) % ring_buffer_size; 271 __func__, dev->ring_head, dev->ring_tail);
272 next_ring_head = (dev->ring_head + 1) % ring_buffer_size;
266 273
267 if (next_ring_head != dev->ring_tail) { 274 if (next_ring_head != dev->ring_tail) {
268 memcpy(&((*dev->ring_buffer)[dev->ring_head]), 275 memcpy(&((*dev->ring_buffer)[dev->ring_head]),
269 dev->interrupt_in_buffer, urb->actual_length); 276 dev->interrupt_in_buffer, urb->actual_length);
270 dev->ring_head = next_ring_head; 277 dev->ring_head = next_ring_head;
271 retval = 0; 278 retval = 0;
272 memset(dev->interrupt_in_buffer, 0, urb->actual_length); 279 memset(dev->interrupt_in_buffer, 0, urb->actual_length);
@@ -330,7 +337,7 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file)
330 337
331 if (!interface) { 338 if (!interface) {
332 err("%s - error, can't find device for minor %d\n", 339 err("%s - error, can't find device for minor %d\n",
333 __func__, subminor); 340 __func__, subminor);
334 retval = -ENODEV; 341 retval = -ENODEV;
335 goto unlock_disconnect_exit; 342 goto unlock_disconnect_exit;
336 } 343 }
@@ -361,11 +368,11 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file)
361 usb_fill_int_urb(dev->interrupt_in_urb, 368 usb_fill_int_urb(dev->interrupt_in_urb,
362 interface_to_usbdev(interface), 369 interface_to_usbdev(interface),
363 usb_rcvintpipe(interface_to_usbdev(interface), 370 usb_rcvintpipe(interface_to_usbdev(interface),
364 dev->interrupt_in_endpoint->bEndpointAddress), 371 dev->interrupt_in_endpoint->
372 bEndpointAddress),
365 dev->interrupt_in_buffer, 373 dev->interrupt_in_buffer,
366 dev->interrupt_in_endpoint_size, 374 dev->interrupt_in_endpoint_size,
367 usb_alphatrack_interrupt_in_callback, 375 usb_alphatrack_interrupt_in_callback, dev,
368 dev,
369 dev->interrupt_in_interval); 376 dev->interrupt_in_interval);
370 377
371 dev->interrupt_in_running = 1; 378 dev->interrupt_in_running = 1;
@@ -375,7 +382,8 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file)
375 382
376 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL); 383 retval = usb_submit_urb(dev->interrupt_in_urb, GFP_KERNEL);
377 if (retval) { 384 if (retval) {
378 dev_err(&interface->dev, "Couldn't submit interrupt_in_urb %d\n", retval); 385 dev_err(&interface->dev,
386 "Couldn't submit interrupt_in_urb %d\n", retval);
379 dev->interrupt_in_running = 0; 387 dev->interrupt_in_running = 0;
380 dev->open_count = 0; 388 dev->open_count = 0;
381 goto unlock_exit; 389 goto unlock_exit;
@@ -384,7 +392,6 @@ static int usb_alphatrack_open(struct inode *inode, struct file *file)
384 /* save device in the file's private structure */ 392 /* save device in the file's private structure */
385 file->private_data = dev; 393 file->private_data = dev;
386 394
387
388unlock_exit: 395unlock_exit:
389 up(&dev->sem); 396 up(&dev->sem);
390 397
@@ -430,7 +437,9 @@ static int usb_alphatrack_release(struct inode *inode, struct file *file)
430 437
431 /* wait until write transfer is finished */ 438 /* wait until write transfer is finished */
432 if (dev->interrupt_out_busy) 439 if (dev->interrupt_out_busy)
433 wait_event_interruptible_timeout(dev->write_wait, !dev->interrupt_out_busy, 2 * HZ); 440 wait_event_interruptible_timeout(dev->write_wait,
441 !dev->interrupt_out_busy,
442 2 * HZ);
434 usb_alphatrack_abort_transfers(dev); 443 usb_alphatrack_abort_transfers(dev);
435 dev->open_count = 0; 444 dev->open_count = 0;
436 445
@@ -444,7 +453,7 @@ exit:
444/** 453/**
445 * usb_alphatrack_poll 454 * usb_alphatrack_poll
446 */ 455 */
447static unsigned int usb_alphatrack_poll(struct file *file, poll_table *wait) 456static unsigned int usb_alphatrack_poll(struct file *file, poll_table * wait)
448{ 457{
449 struct usb_alphatrack *dev; 458 struct usb_alphatrack *dev;
450 unsigned int mask = 0; 459 unsigned int mask = 0;
@@ -465,8 +474,8 @@ static unsigned int usb_alphatrack_poll(struct file *file, poll_table *wait)
465/** 474/**
466 * usb_alphatrack_read 475 * usb_alphatrack_read
467 */ 476 */
468static ssize_t usb_alphatrack_read(struct file *file, char __user *buffer, size_t count, 477static ssize_t usb_alphatrack_read(struct file *file, char __user *buffer,
469 loff_t *ppos) 478 size_t count, loff_t *ppos)
470{ 479{
471 struct usb_alphatrack *dev; 480 struct usb_alphatrack *dev;
472 int retval = 0; 481 int retval = 0;
@@ -493,30 +502,36 @@ static ssize_t usb_alphatrack_read(struct file *file, char __user *buffer, size_
493 } 502 }
494 503
495 while (dev->ring_head == dev->ring_tail) { 504 while (dev->ring_head == dev->ring_tail) {
496 if (file->f_flags & O_NONBLOCK) { 505 if (file->f_flags & O_NONBLOCK) {
497 retval = -EAGAIN; 506 retval = -EAGAIN;
498 goto unlock_exit; 507 goto unlock_exit;
499 } 508 }
500 dev->interrupt_in_done = 0 ; 509 dev->interrupt_in_done = 0;
501 retval = wait_event_interruptible(dev->read_wait, dev->interrupt_in_done); 510 retval =
502 if (retval < 0) { 511 wait_event_interruptible(dev->read_wait,
503 goto unlock_exit; 512 dev->interrupt_in_done);
504 } 513 if (retval < 0)
505 } 514 goto unlock_exit;
506 515 }
507 alphatrack_ocmd_info(&dev->intf->dev, &(*dev->ring_buffer)[dev->ring_tail].cmd, "%s", ": copying to userspace"); 516
508 517 alphatrack_ocmd_info(&dev->intf->dev,
509 c = 0; 518 &(*dev->ring_buffer)[dev->ring_tail].cmd, "%s",
510 while((c < count) && (dev->ring_tail != dev->ring_head)) { 519 ": copying to userspace");
511 if (copy_to_user(&buffer[c], &(*dev->ring_buffer)[dev->ring_tail], INPUT_CMD_SIZE)) { 520
512 retval = -EFAULT; 521 c = 0;
513 goto unlock_exit; 522 while ((c < count) && (dev->ring_tail != dev->ring_head)) {
514 } 523 if (copy_to_user
515 dev->ring_tail = (dev->ring_tail+1) % ring_buffer_size; 524 (&buffer[c], &(*dev->ring_buffer)[dev->ring_tail],
516 c+=INPUT_CMD_SIZE; 525 INPUT_CMD_SIZE)) {
517 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n", __func__,dev->ring_head,dev->ring_tail); 526 retval = -EFAULT;
518 } 527 goto unlock_exit;
519 retval = c; 528 }
529 dev->ring_tail = (dev->ring_tail + 1) % ring_buffer_size;
530 c += INPUT_CMD_SIZE;
531 dbg_info(&dev->intf->dev, "%s: head, tail are %x, %x\n",
532 __func__, dev->ring_head, dev->ring_tail);
533 }
534 retval = c;
520 535
521unlock_exit: 536unlock_exit:
522 /* unlock the device */ 537 /* unlock the device */
@@ -529,8 +544,9 @@ exit:
529/** 544/**
530 * usb_alphatrack_write 545 * usb_alphatrack_write
531 */ 546 */
532static ssize_t usb_alphatrack_write(struct file *file, const char __user *buffer, 547static ssize_t usb_alphatrack_write(struct file *file,
533 size_t count, loff_t *ppos) 548 const char __user *buffer, size_t count,
549 loff_t *ppos)
534{ 550{
535 struct usb_alphatrack *dev; 551 struct usb_alphatrack *dev;
536 size_t bytes_to_write; 552 size_t bytes_to_write;
@@ -561,19 +577,24 @@ static ssize_t usb_alphatrack_write(struct file *file, const char __user *buffer
561 retval = -EAGAIN; 577 retval = -EAGAIN;
562 goto unlock_exit; 578 goto unlock_exit;
563 } 579 }
564 retval = wait_event_interruptible(dev->write_wait, !dev->interrupt_out_busy); 580 retval =
565 if (retval < 0) { 581 wait_event_interruptible(dev->write_wait,
582 !dev->interrupt_out_busy);
583 if (retval < 0)
566 goto unlock_exit; 584 goto unlock_exit;
567 }
568 } 585 }
569 586
570 /* write the data into interrupt_out_buffer from userspace */ 587 /* write the data into interrupt_out_buffer from userspace */
571 /* FIXME - if you write more than 12 bytes this breaks */ 588 /* FIXME - if you write more than 12 bytes this breaks */
572 bytes_to_write = min(count, write_buffer_size*dev->interrupt_out_endpoint_size); 589 bytes_to_write =
590 min(count, write_buffer_size * dev->interrupt_out_endpoint_size);
573 if (bytes_to_write < count) 591 if (bytes_to_write < count)
574 dev_warn(&dev->intf->dev, "Write buffer overflow, %zd bytes dropped\n",count-bytes_to_write); 592 dev_warn(&dev->intf->dev,
593 "Write buffer overflow, %zd bytes dropped\n",
594 count - bytes_to_write);
575 595
576 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n", __func__, count, bytes_to_write); 596 dbg_info(&dev->intf->dev, "%s: count = %zd, bytes_to_write = %zd\n",
597 __func__, count, bytes_to_write);
577 598
578 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) { 599 if (copy_from_user(dev->interrupt_out_buffer, buffer, bytes_to_write)) {
579 retval = -EFAULT; 600 retval = -EFAULT;
@@ -589,11 +610,10 @@ static ssize_t usb_alphatrack_write(struct file *file, const char __user *buffer
589 usb_fill_int_urb(dev->interrupt_out_urb, 610 usb_fill_int_urb(dev->interrupt_out_urb,
590 interface_to_usbdev(dev->intf), 611 interface_to_usbdev(dev->intf),
591 usb_sndintpipe(interface_to_usbdev(dev->intf), 612 usb_sndintpipe(interface_to_usbdev(dev->intf),
592 dev->interrupt_out_endpoint->bEndpointAddress), 613 dev->interrupt_out_endpoint->
593 dev->interrupt_out_buffer, 614 bEndpointAddress),
594 bytes_to_write, 615 dev->interrupt_out_buffer, bytes_to_write,
595 usb_alphatrack_interrupt_out_callback, 616 usb_alphatrack_interrupt_out_callback, dev,
596 dev,
597 dev->interrupt_out_interval); 617 dev->interrupt_out_interval);
598 dev->interrupt_out_busy = 1; 618 dev->interrupt_out_busy = 1;
599 atomic_inc(&dev->writes_pending); 619 atomic_inc(&dev->writes_pending);
@@ -618,12 +638,12 @@ exit:
618 638
619/* file operations needed when we register this driver */ 639/* file operations needed when we register this driver */
620static const struct file_operations usb_alphatrack_fops = { 640static const struct file_operations usb_alphatrack_fops = {
621 .owner = THIS_MODULE, 641 .owner = THIS_MODULE,
622 .read = usb_alphatrack_read, 642 .read = usb_alphatrack_read,
623 .write = usb_alphatrack_write, 643 .write = usb_alphatrack_write,
624 .open = usb_alphatrack_open, 644 .open = usb_alphatrack_open,
625 .release = usb_alphatrack_release, 645 .release = usb_alphatrack_release,
626 .poll = usb_alphatrack_poll, 646 .poll = usb_alphatrack_poll,
627}; 647};
628 648
629/* 649/*
@@ -632,19 +652,19 @@ static const struct file_operations usb_alphatrack_fops = {
632 */ 652 */
633 653
634static struct usb_class_driver usb_alphatrack_class = { 654static struct usb_class_driver usb_alphatrack_class = {
635 .name = "alphatrack%d", 655 .name = "alphatrack%d",
636 .fops = &usb_alphatrack_fops, 656 .fops = &usb_alphatrack_fops,
637 .minor_base = USB_ALPHATRACK_MINOR_BASE, 657 .minor_base = USB_ALPHATRACK_MINOR_BASE,
638}; 658};
639 659
640
641/** 660/**
642 * usb_alphatrack_probe 661 * usb_alphatrack_probe
643 * 662 *
644 * Called by the usb core when a new device is connected that it thinks 663 * Called by the usb core when a new device is connected that it thinks
645 * this driver might be interested in. 664 * this driver might be interested in.
646 */ 665 */
647static int usb_alphatrack_probe(struct usb_interface *intf, const struct usb_device_id *id) 666static int usb_alphatrack_probe(struct usb_interface *intf,
667 const struct usb_device_id *id)
648{ 668{
649 struct usb_device *udev = interface_to_usbdev(intf); 669 struct usb_device *udev = interface_to_usbdev(intf);
650 struct usb_alphatrack *dev = NULL; 670 struct usb_alphatrack *dev = NULL;
@@ -683,28 +703,35 @@ static int usb_alphatrack_probe(struct usb_interface *intf, const struct usb_dev
683 goto error; 703 goto error;
684 } 704 }
685 if (dev->interrupt_out_endpoint == NULL) 705 if (dev->interrupt_out_endpoint == NULL)
686 dev_warn(&intf->dev, "Interrupt out endpoint not found (using control endpoint instead)\n"); 706 dev_warn(&intf->dev,
707 "Interrupt out endpoint not found"
708 "(using control endpoint instead)\n");
687 709
688 dev->interrupt_in_endpoint_size = le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize); 710 dev->interrupt_in_endpoint_size =
711 le16_to_cpu(dev->interrupt_in_endpoint->wMaxPacketSize);
689 712
690 if (dev->interrupt_in_endpoint_size != 64) 713 if (dev->interrupt_in_endpoint_size != 64)
691 dev_warn(&intf->dev, "Interrupt in endpoint size is not 64!\n"); 714 dev_warn(&intf->dev, "Interrupt in endpoint size is not 64!\n");
692
693 if(ring_buffer_size == 0) { ring_buffer_size = RING_BUFFER_SIZE; }
694 715
695 true_size = min(ring_buffer_size,RING_BUFFER_SIZE); 716 if (ring_buffer_size == 0)
717 ring_buffer_size = RING_BUFFER_SIZE;
696 718
697 /* FIXME - there are more usb_alloc routines for dma correctness. Needed? */ 719 true_size = min(ring_buffer_size, RING_BUFFER_SIZE);
698 720
699// dev->ring_buffer = kmalloc((true_size*sizeof(struct alphatrack_icmd))+12, GFP_KERNEL); 721 /* FIXME - there are more usb_alloc routines for dma correctness.
700 dev->ring_buffer = kmalloc((true_size*sizeof(struct alphatrack_icmd)), GFP_KERNEL); 722 Needed? */
723 dev->ring_buffer =
724 kmalloc((true_size * sizeof(struct alphatrack_icmd)), GFP_KERNEL);
701 725
702 if (!dev->ring_buffer) { 726 if (!dev->ring_buffer) {
703 dev_err(&intf->dev, "Couldn't allocate input ring_buffer of size %d\n",true_size); 727 dev_err(&intf->dev,
728 "Couldn't allocate input ring_buffer of size %d\n",
729 true_size);
704 goto error; 730 goto error;
705 } 731 }
706 732
707 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); 733 dev->interrupt_in_buffer =
734 kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
708 735
709 if (!dev->interrupt_in_buffer) { 736 if (!dev->interrupt_in_buffer) {
710 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n"); 737 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
@@ -721,23 +748,30 @@ static int usb_alphatrack_probe(struct usb_interface *intf, const struct usb_dev
721 goto error; 748 goto error;
722 } 749 }
723 750
724 dev->interrupt_out_endpoint_size = dev->interrupt_out_endpoint ? le16_to_cpu(dev->interrupt_out_endpoint->wMaxPacketSize) : 751 dev->interrupt_out_endpoint_size =
725 udev->descriptor.bMaxPacketSize0; 752 dev->interrupt_out_endpoint ? le16_to_cpu(dev->
753 interrupt_out_endpoint->
754 wMaxPacketSize) : udev->
755 descriptor.bMaxPacketSize0;
726 756
727 if (dev->interrupt_out_endpoint_size !=64) 757 if (dev->interrupt_out_endpoint_size != 64)
728 dev_warn(&intf->dev, "Interrupt out endpoint size is not 64!)\n"); 758 dev_warn(&intf->dev,
759 "Interrupt out endpoint size is not 64!)\n");
729 760
730 if(write_buffer_size == 0) { write_buffer_size = WRITE_BUFFER_SIZE; } 761 if (write_buffer_size == 0)
731 true_size = min(write_buffer_size,WRITE_BUFFER_SIZE); 762 write_buffer_size = WRITE_BUFFER_SIZE;
763 true_size = min(write_buffer_size, WRITE_BUFFER_SIZE);
732 764
733 dev->interrupt_out_buffer = kmalloc(true_size*dev->interrupt_out_endpoint_size, GFP_KERNEL); 765 dev->interrupt_out_buffer =
766 kmalloc(true_size * dev->interrupt_out_endpoint_size, GFP_KERNEL);
734 767
735 if (!dev->interrupt_out_buffer) { 768 if (!dev->interrupt_out_buffer) {
736 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n"); 769 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
737 goto error; 770 goto error;
738 } 771 }
739 772
740 dev->write_buffer = kmalloc(sizeof(struct alphatrack_ocmd)*true_size, GFP_KERNEL); 773 dev->write_buffer =
774 kmalloc(sizeof(struct alphatrack_ocmd) * true_size, GFP_KERNEL);
741 775
742 if (!dev->write_buffer) { 776 if (!dev->write_buffer) {
743 dev_err(&intf->dev, "Couldn't allocate write_buffer \n"); 777 dev_err(&intf->dev, "Couldn't allocate write_buffer \n");
@@ -749,25 +783,36 @@ static int usb_alphatrack_probe(struct usb_interface *intf, const struct usb_dev
749 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n"); 783 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
750 goto error; 784 goto error;
751 } 785 }
752 dev->interrupt_in_interval = min_interrupt_in_interval > dev->interrupt_in_endpoint->bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->bInterval; 786 dev->interrupt_in_interval =
787 min_interrupt_in_interval >
788 dev->interrupt_in_endpoint->
789 bInterval ? min_interrupt_in_interval : dev->interrupt_in_endpoint->
790 bInterval;
753 if (dev->interrupt_out_endpoint) 791 if (dev->interrupt_out_endpoint)
754 dev->interrupt_out_interval = min_interrupt_out_interval > dev->interrupt_out_endpoint->bInterval ? min_interrupt_out_interval : dev->interrupt_out_endpoint->bInterval; 792 dev->interrupt_out_interval =
793 min_interrupt_out_interval >
794 dev->interrupt_out_endpoint->
795 bInterval ? min_interrupt_out_interval : dev->
796 interrupt_out_endpoint->bInterval;
755 797
756 /* we can register the device now, as it is ready */ 798 /* we can register the device now, as it is ready */
757 usb_set_intfdata(intf, dev); 799 usb_set_intfdata(intf, dev);
758 800
759 atomic_set(&dev->writes_pending,0); 801 atomic_set(&dev->writes_pending, 0);
760 retval = usb_register_dev(intf, &usb_alphatrack_class); 802 retval = usb_register_dev(intf, &usb_alphatrack_class);
761 if (retval) { 803 if (retval) {
762 /* something prevented us from registering this driver */ 804 /* something prevented us from registering this driver */
763 dev_err(&intf->dev, "Not able to get a minor for this device.\n"); 805 dev_err(&intf->dev,
806 "Not able to get a minor for this device.\n");
764 usb_set_intfdata(intf, NULL); 807 usb_set_intfdata(intf, NULL);
765 goto error; 808 goto error;
766 } 809 }
767 810
768 /* let the user know what node this device is now attached to */ 811 /* let the user know what node this device is now attached to */
769 dev_info(&intf->dev, "Alphatrack Device #%d now attached to major %d minor %d\n", 812 dev_info(&intf->dev,
770 (intf->minor - USB_ALPHATRACK_MINOR_BASE), USB_MAJOR, intf->minor); 813 "Alphatrack Device #%d now attached to major %d minor %d\n",
814 (intf->minor - USB_ALPHATRACK_MINOR_BASE), USB_MAJOR,
815 intf->minor);
771 816
772exit: 817exit:
773 return retval; 818 return retval;
@@ -809,7 +854,7 @@ static void usb_alphatrack_disconnect(struct usb_interface *intf)
809 up(&dev->sem); 854 up(&dev->sem);
810 } 855 }
811 856
812 atomic_set(&dev->writes_pending,0); 857 atomic_set(&dev->writes_pending, 0);
813 mutex_unlock(&disconnect_mutex); 858 mutex_unlock(&disconnect_mutex);
814 859
815 dev_info(&intf->dev, "Alphatrack Surface #%d now disconnected\n", 860 dev_info(&intf->dev, "Alphatrack Surface #%d now disconnected\n",
@@ -818,10 +863,10 @@ static void usb_alphatrack_disconnect(struct usb_interface *intf)
818 863
819/* usb specific object needed to register this driver with the usb subsystem */ 864/* usb specific object needed to register this driver with the usb subsystem */
820static struct usb_driver usb_alphatrack_driver = { 865static struct usb_driver usb_alphatrack_driver = {
821 .name = "alphatrack", 866 .name = "alphatrack",
822 .probe = usb_alphatrack_probe, 867 .probe = usb_alphatrack_probe,
823 .disconnect = usb_alphatrack_disconnect, 868 .disconnect = usb_alphatrack_disconnect,
824 .id_table = usb_alphatrack_table, 869 .id_table = usb_alphatrack_table,
825}; 870};
826 871
827/** 872/**
@@ -834,7 +879,8 @@ static int __init usb_alphatrack_init(void)
834 /* register this driver with the USB subsystem */ 879 /* register this driver with the USB subsystem */
835 retval = usb_register(&usb_alphatrack_driver); 880 retval = usb_register(&usb_alphatrack_driver);
836 if (retval) 881 if (retval)
837 err("usb_register failed for the "__FILE__" driver. Error number %d\n", retval); 882 err("usb_register failed for the " __FILE__
883 " driver. Error number %d\n", retval);
838 884
839 return retval; 885 return retval;
840} 886}
@@ -850,4 +896,3 @@ static void __exit usb_alphatrack_exit(void)
850 896
851module_init(usb_alphatrack_init); 897module_init(usb_alphatrack_init);
852module_exit(usb_alphatrack_exit); 898module_exit(usb_alphatrack_exit);
853