31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/signal.h>
34 #include <linux/sched.h>
36 #include <linux/errno.h>
37 #include <linux/random.h>
38 #include <linux/poll.h>
40 #include <linux/slab.h>
43 #include <linux/wait.h>
50 #define DRIVER_VERSION "v1.1"
52 #define DRIVER_DESC "USB Rio 500 driver"
57 #define NAK_TIMEOUT (HZ)
59 #define IBUF_SIZE 0x1000
62 #define OBUF_SIZE 0x10000
103 static int close_rio(
struct inode *inode,
struct file *file)
113 static long ioctl_rio(
struct file *file,
unsigned int cmd,
unsigned long arg)
132 data = (
void __user *) arg;
139 if (rio_cmd.length < 0 || rio_cmd.length >
PAGE_SIZE) {
144 if (buffer ==
NULL) {
154 requesttype = rio_cmd.requesttype |
USB_DIR_IN |
157 "sending command:reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
158 requesttype, rio_cmd.request, rio_cmd.value,
159 rio_cmd.index, rio_cmd.length);
164 usb_rcvctrlpipe(rio->
rio_dev, 0),
168 rio_cmd.index, buffer,
173 else if (result < 0) {
175 "Error executing ioctrl. code = %d\n",
180 "Executed ioctl. Result = %d (data=%02x)\n",
203 data = (
void __user *) arg;
210 if (rio_cmd.length < 0 || rio_cmd.length >
PAGE_SIZE) {
215 if (buffer ==
NULL) {
228 "sending command: reqtype=%0x req=%0x value=%0x index=%0x len=%0x\n",
229 requesttype, rio_cmd.request, rio_cmd.value,
230 rio_cmd.index, rio_cmd.length);
235 usb_sndctrlpipe(rio->
rio_dev, 0),
239 rio_cmd.index, buffer,
244 else if (result < 0) {
246 "Error executing ioctrl. code = %d\n",
251 "Executed ioctl. Result = %d\n", result);
272 write_rio(
struct file *file,
const char __user *buffer,
273 size_t count, loff_t * ppos)
278 unsigned long copy_size;
279 unsigned long bytes_written = 0;
280 unsigned int partial;
299 unsigned long thistime;
302 thistime = copy_size =
316 return bytes_written ? bytes_written : -
EINTR;
320 usb_sndbulkpipe(rio->
rio_dev, 2),
321 obuf, thistime, &partial, 5000);
324 "write stats: result:%d thistime:%lu partial:%u\n",
325 result, thistime, partial);
336 }
else if (!result && partial) {
348 bytes_written += copy_size;
355 return bytes_written ? bytes_written : -
EIO;
363 read_rio(
struct file *file,
char __user *buffer,
size_t count, loff_t * ppos)
368 unsigned int partial;
392 return read_count ? read_count : -
EINTR;
401 usb_rcvbulkpipe(rio->
rio_dev, 1),
402 ibuf, this_read, &partial,
406 "read stats: result:%d this_read:%u partial:%u\n",
407 result, this_read, partial);
410 count = this_read = partial;
411 }
else if (result == -
ETIMEDOUT || result == 15) {
415 "read_rio: maxretry timeout\n");
425 "Read Whoops - result:%u partial:%u this_read:%u\n",
426 result, partial, this_read);
439 read_count += this_read;
451 .unlocked_ioctl = ioctl_rio,
453 .release = close_rio,
457 static struct usb_class_driver usb_rio_class = {
459 .fops = &usb_rio_fops,
466 struct usb_device *
dev = interface_to_usbdev(intf);
470 dev_info(&intf->dev,
"USB Rio found at address %d\n", dev->devnum);
475 "Not able to get a minor for this device.\n");
483 "probe_rio: Not enough memory for the output buffer\n");
487 dev_dbg(&intf->dev,
"obuf address:%p\n", rio->
obuf);
491 "probe_rio: Not enough memory for the input buffer\n");
496 dev_dbg(&intf->dev,
"ibuf address:%p\n", rio->
ibuf);
500 usb_set_intfdata (intf, rio);
510 usb_set_intfdata (intf,
NULL);
527 dev_info(&intf->dev,
"USB Rio disconnected.\n");
536 { USB_DEVICE(0x0841, 1) },
545 .disconnect = disconnect_rio,
546 .id_table = rio_table,