Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Empeg empeg-car player driver |
| 3 | * |
| 4 | * Copyright (C) 2000, 2001 |
| 5 | * Gary Brubaker (xavyer@ix.netcom.com) |
| 6 | * |
| 7 | * Copyright (C) 1999 - 2001 |
| 8 | * Greg Kroah-Hartman (greg@kroah.com) |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License, as published by |
| 12 | * the Free Software Foundation, version 2. |
| 13 | * |
| 14 | * See Documentation/usb/usb-serial.txt for more information on using this driver |
| 15 | * |
| 16 | * (07/16/2001) gb |
| 17 | * remove unused code in empeg_close() (thanks to Oliver Neukum for pointing this |
| 18 | * out) and rewrote empeg_set_termios(). |
| 19 | * |
| 20 | * (05/30/2001) gkh |
| 21 | * switched from using spinlock to a semaphore, which fixes lots of problems. |
| 22 | * |
| 23 | * (04/08/2001) gb |
| 24 | * Identify version on module load. |
| 25 | * |
| 26 | * (01/22/2001) gb |
| 27 | * Added write_room() and chars_in_buffer() support. |
| 28 | * |
| 29 | * (12/21/2000) gb |
| 30 | * Moved termio stuff inside the port->active check. |
| 31 | * Moved MOD_DEC_USE_COUNT to end of empeg_close(). |
| 32 | * |
| 33 | * (12/03/2000) gb |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 34 | * Added port->port.tty->ldisc.set_termios(port->port.tty, NULL) to empeg_open() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * This notifies the tty driver that the termios have changed. |
| 36 | * |
| 37 | * (11/13/2000) gb |
| 38 | * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to empeg_open() |
| 39 | * (It only needs to be set once - Doh!) |
| 40 | * |
| 41 | * (11/11/2000) gb |
| 42 | * Updated to work with id_table structure. |
| 43 | * |
| 44 | * (11/04/2000) gb |
| 45 | * Forked this from visor.c, and hacked it up to work with an |
| 46 | * Empeg ltd. empeg-car player. Constructive criticism welcomed. |
| 47 | * I would like to say, 'Thank You' to Greg Kroah-Hartman for the |
| 48 | * use of his code, and for his guidance, advice and patience. :) |
| 49 | * A 'Thank You' is in order for John Ripley of Empeg ltd for his |
| 50 | * advice, and patience too. |
| 51 | * |
| 52 | */ |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <linux/kernel.h> |
| 55 | #include <linux/errno.h> |
| 56 | #include <linux/init.h> |
| 57 | #include <linux/slab.h> |
| 58 | #include <linux/tty.h> |
| 59 | #include <linux/tty_driver.h> |
| 60 | #include <linux/tty_flip.h> |
| 61 | #include <linux/module.h> |
| 62 | #include <linux/spinlock.h> |
| 63 | #include <asm/uaccess.h> |
| 64 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 65 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | static int debug; |
| 68 | |
| 69 | /* |
| 70 | * Version Information |
| 71 | */ |
| 72 | #define DRIVER_VERSION "v1.2" |
| 73 | #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>" |
| 74 | #define DRIVER_DESC "USB Empeg Mark I/II Driver" |
| 75 | |
| 76 | #define EMPEG_VENDOR_ID 0x084f |
| 77 | #define EMPEG_PRODUCT_ID 0x0001 |
| 78 | |
| 79 | /* function prototypes for an empeg-car player */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 80 | static int empeg_open (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); |
| 81 | static void empeg_close (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); |
| 82 | static int empeg_write (struct tty_struct *tty, struct usb_serial_port *port, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | const unsigned char *buf, |
| 84 | int count); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 85 | static int empeg_write_room (struct tty_struct *tty); |
| 86 | static int empeg_chars_in_buffer (struct tty_struct *tty); |
| 87 | static void empeg_throttle (struct tty_struct *tty); |
| 88 | static void empeg_unthrottle (struct tty_struct *tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static int empeg_startup (struct usb_serial *serial); |
| 90 | static void empeg_shutdown (struct usb_serial *serial); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 91 | static void empeg_set_termios (struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 92 | static void empeg_write_bulk_callback (struct urb *urb); |
| 93 | static void empeg_read_bulk_callback (struct urb *urb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
| 95 | static struct usb_device_id id_table [] = { |
| 96 | { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, |
| 97 | { } /* Terminating entry */ |
| 98 | }; |
| 99 | |
| 100 | MODULE_DEVICE_TABLE (usb, id_table); |
| 101 | |
| 102 | static struct usb_driver empeg_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | .name = "empeg", |
| 104 | .probe = usb_serial_probe, |
| 105 | .disconnect = usb_serial_disconnect, |
| 106 | .id_table = id_table, |
Greg Kroah-Hartman | ba9dc65 | 2005-11-16 13:41:28 -0800 | [diff] [blame] | 107 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 110 | static struct usb_serial_driver empeg_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 111 | .driver = { |
| 112 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 113 | .name = "empeg", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 114 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | .id_table = id_table, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 116 | .usb_driver = &empeg_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | .num_ports = 1, |
| 118 | .open = empeg_open, |
| 119 | .close = empeg_close, |
| 120 | .throttle = empeg_throttle, |
| 121 | .unthrottle = empeg_unthrottle, |
| 122 | .attach = empeg_startup, |
| 123 | .shutdown = empeg_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | .set_termios = empeg_set_termios, |
| 125 | .write = empeg_write, |
| 126 | .write_room = empeg_write_room, |
| 127 | .chars_in_buffer = empeg_chars_in_buffer, |
| 128 | .write_bulk_callback = empeg_write_bulk_callback, |
| 129 | .read_bulk_callback = empeg_read_bulk_callback, |
| 130 | }; |
| 131 | |
| 132 | #define NUM_URBS 16 |
| 133 | #define URB_TRANSFER_BUFFER_SIZE 4096 |
| 134 | |
| 135 | static struct urb *write_urb_pool[NUM_URBS]; |
| 136 | static spinlock_t write_urb_pool_lock; |
| 137 | static int bytes_in; |
| 138 | static int bytes_out; |
| 139 | |
| 140 | /****************************************************************************** |
| 141 | * Empeg specific driver functions |
| 142 | ******************************************************************************/ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 143 | static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, |
| 144 | struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | struct usb_serial *serial = port->serial; |
| 147 | int result = 0; |
| 148 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 149 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | /* Force default termio settings */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 152 | empeg_set_termios (tty, port, NULL) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | bytes_in = 0; |
| 155 | bytes_out = 0; |
| 156 | |
| 157 | /* Start reading from the device */ |
| 158 | usb_fill_bulk_urb( |
| 159 | port->read_urb, |
| 160 | serial->dev, |
| 161 | usb_rcvbulkpipe(serial->dev, |
| 162 | port->bulk_in_endpointAddress), |
| 163 | port->read_urb->transfer_buffer, |
| 164 | port->read_urb->transfer_buffer_length, |
| 165 | empeg_read_bulk_callback, |
| 166 | port); |
| 167 | |
| 168 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 169 | |
| 170 | if (result) |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 171 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | return result; |
| 174 | } |
| 175 | |
| 176 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 177 | static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, |
| 178 | struct file * filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 180 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | /* shutdown our bulk read */ |
| 183 | usb_kill_urb(port->read_urb); |
| 184 | /* Uncomment the following line if you want to see some statistics in your syslog */ |
| 185 | /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */ |
| 186 | } |
| 187 | |
| 188 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 189 | static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
| 191 | struct usb_serial *serial = port->serial; |
| 192 | struct urb *urb; |
| 193 | const unsigned char *current_position = buf; |
| 194 | unsigned long flags; |
| 195 | int status; |
| 196 | int i; |
| 197 | int bytes_sent = 0; |
| 198 | int transfer_size; |
| 199 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 200 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | while (count > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | /* try to find a free urb in our list of them */ |
| 204 | urb = NULL; |
| 205 | |
| 206 | spin_lock_irqsave (&write_urb_pool_lock, flags); |
| 207 | |
| 208 | for (i = 0; i < NUM_URBS; ++i) { |
| 209 | if (write_urb_pool[i]->status != -EINPROGRESS) { |
| 210 | urb = write_urb_pool[i]; |
| 211 | break; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | spin_unlock_irqrestore (&write_urb_pool_lock, flags); |
| 216 | |
| 217 | if (urb == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 218 | dbg("%s - no more free urbs", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | goto exit; |
| 220 | } |
| 221 | |
| 222 | if (urb->transfer_buffer == NULL) { |
| 223 | urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); |
| 224 | if (urb->transfer_buffer == NULL) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 225 | dev_err(&port->dev, "%s no more kernel memory...\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | goto exit; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); |
| 231 | |
| 232 | memcpy (urb->transfer_buffer, current_position, transfer_size); |
| 233 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 234 | usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | /* build up our urb */ |
| 237 | usb_fill_bulk_urb ( |
| 238 | urb, |
| 239 | serial->dev, |
| 240 | usb_sndbulkpipe(serial->dev, |
| 241 | port->bulk_out_endpointAddress), |
| 242 | urb->transfer_buffer, |
| 243 | transfer_size, |
| 244 | empeg_write_bulk_callback, |
| 245 | port); |
| 246 | |
| 247 | /* send it down the pipe */ |
| 248 | status = usb_submit_urb(urb, GFP_ATOMIC); |
| 249 | if (status) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 250 | dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | bytes_sent = status; |
| 252 | break; |
| 253 | } |
| 254 | |
| 255 | current_position += transfer_size; |
| 256 | bytes_sent += transfer_size; |
| 257 | count -= transfer_size; |
| 258 | bytes_out += transfer_size; |
| 259 | |
| 260 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | exit: |
| 262 | return bytes_sent; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 266 | static int empeg_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 268 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | unsigned long flags; |
| 270 | int i; |
| 271 | int room = 0; |
| 272 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 273 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | spin_lock_irqsave (&write_urb_pool_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* tally up the number of bytes available */ |
| 277 | for (i = 0; i < NUM_URBS; ++i) { |
| 278 | if (write_urb_pool[i]->status != -EINPROGRESS) { |
| 279 | room += URB_TRANSFER_BUFFER_SIZE; |
| 280 | } |
| 281 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | spin_unlock_irqrestore (&write_urb_pool_lock, flags); |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 283 | dbg("%s - returns %d", __func__, room); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 284 | return room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | } |
| 287 | |
| 288 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 289 | static int empeg_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 291 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | unsigned long flags; |
| 293 | int i; |
| 294 | int chars = 0; |
| 295 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 296 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
| 298 | spin_lock_irqsave (&write_urb_pool_lock, flags); |
| 299 | |
| 300 | /* tally up the number of bytes waiting */ |
| 301 | for (i = 0; i < NUM_URBS; ++i) { |
| 302 | if (write_urb_pool[i]->status == -EINPROGRESS) { |
| 303 | chars += URB_TRANSFER_BUFFER_SIZE; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | spin_unlock_irqrestore (&write_urb_pool_lock, flags); |
| 308 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 309 | dbg("%s - returns %d", __func__, chars); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
| 311 | return (chars); |
| 312 | |
| 313 | } |
| 314 | |
| 315 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 316 | static void empeg_write_bulk_callback (struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
Greg Kroah-Hartman | 335202f | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 318 | struct usb_serial_port *port = urb->context; |
| 319 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 321 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Greg Kroah-Hartman | 335202f | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 323 | if (status) { |
| 324 | dbg("%s - nonzero write bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 325 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return; |
| 327 | } |
| 328 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 329 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 333 | static void empeg_read_bulk_callback (struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 335 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | struct tty_struct *tty; |
| 337 | unsigned char *data = urb->transfer_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | int result; |
Greg Kroah-Hartman | 335202f | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 339 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 341 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Greg Kroah-Hartman | 335202f | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 343 | if (status) { |
| 344 | dbg("%s - nonzero read bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 345 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return; |
| 347 | } |
| 348 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 349 | usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 351 | tty = port->port.tty; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
| 353 | if (urb->actual_length) { |
Alan Cox | 33f0f88 | 2006-01-09 20:54:13 -0800 | [diff] [blame] | 354 | tty_buffer_request_room(tty, urb->actual_length); |
| 355 | tty_insert_flip_string(tty, data, urb->actual_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | tty_flip_buffer_push(tty); |
| 357 | bytes_in += urb->actual_length; |
| 358 | } |
| 359 | |
| 360 | /* Continue trying to always read */ |
| 361 | usb_fill_bulk_urb( |
| 362 | port->read_urb, |
| 363 | port->serial->dev, |
| 364 | usb_rcvbulkpipe(port->serial->dev, |
| 365 | port->bulk_in_endpointAddress), |
| 366 | port->read_urb->transfer_buffer, |
| 367 | port->read_urb->transfer_buffer_length, |
| 368 | empeg_read_bulk_callback, |
| 369 | port); |
| 370 | |
| 371 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
| 372 | |
| 373 | if (result) |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 374 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | return; |
| 377 | |
| 378 | } |
| 379 | |
| 380 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 381 | static void empeg_throttle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 383 | struct usb_serial_port *port = tty->driver_data; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 384 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | usb_kill_urb(port->read_urb); |
| 386 | } |
| 387 | |
| 388 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 389 | static void empeg_unthrottle(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 391 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | int result; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 393 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | port->read_urb->dev = port->serial->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | result = usb_submit_urb(port->read_urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | if (result) |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 398 | dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | |
| 402 | static int empeg_startup (struct usb_serial *serial) |
| 403 | { |
| 404 | int r; |
| 405 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 406 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | if (serial->dev->actconfig->desc.bConfigurationValue != 1) { |
| 409 | err("active config #%d != 1 ??", |
| 410 | serial->dev->actconfig->desc.bConfigurationValue); |
| 411 | return -ENODEV; |
| 412 | } |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 413 | dbg("%s - reset config", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | r = usb_reset_configuration (serial->dev); |
| 415 | |
| 416 | /* continue on with initialization */ |
| 417 | return r; |
| 418 | |
| 419 | } |
| 420 | |
| 421 | |
| 422 | static void empeg_shutdown (struct usb_serial *serial) |
| 423 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 424 | dbg ("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 428 | static void empeg_set_termios(struct tty_struct *tty, |
| 429 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 431 | struct ktermios *termios = tty->termios; |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 432 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | /* |
| 435 | * The empeg-car player wants these particular tty settings. |
| 436 | * You could, for example, change the baud rate, however the |
| 437 | * player only supports 115200 (currently), so there is really |
| 438 | * no point in support for changes to the tty settings. |
| 439 | * (at least for now) |
| 440 | * |
| 441 | * The default requirements for this device are: |
| 442 | */ |
Alan Cox | 998e863 | 2007-10-18 01:24:19 -0700 | [diff] [blame] | 443 | termios->c_iflag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | &= ~(IGNBRK /* disable ignore break */ |
| 445 | | BRKINT /* disable break causes interrupt */ |
| 446 | | PARMRK /* disable mark parity errors */ |
| 447 | | ISTRIP /* disable clear high bit of input characters */ |
| 448 | | INLCR /* disable translate NL to CR */ |
| 449 | | IGNCR /* disable ignore CR */ |
| 450 | | ICRNL /* disable translate CR to NL */ |
| 451 | | IXON); /* disable enable XON/XOFF flow control */ |
| 452 | |
Alan Cox | 998e863 | 2007-10-18 01:24:19 -0700 | [diff] [blame] | 453 | termios->c_oflag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | &= ~OPOST; /* disable postprocess output characters */ |
| 455 | |
Alan Cox | 998e863 | 2007-10-18 01:24:19 -0700 | [diff] [blame] | 456 | termios->c_lflag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | &= ~(ECHO /* disable echo input characters */ |
| 458 | | ECHONL /* disable echo new line */ |
| 459 | | ICANON /* disable erase, kill, werase, and rprnt special characters */ |
| 460 | | ISIG /* disable interrupt, quit, and suspend special characters */ |
| 461 | | IEXTEN); /* disable non-POSIX special characters */ |
| 462 | |
Alan Cox | 998e863 | 2007-10-18 01:24:19 -0700 | [diff] [blame] | 463 | termios->c_cflag |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | &= ~(CSIZE /* no size */ |
| 465 | | PARENB /* disable parity bit */ |
| 466 | | CBAUD); /* clear current baud rate */ |
| 467 | |
Alan Cox | 998e863 | 2007-10-18 01:24:19 -0700 | [diff] [blame] | 468 | termios->c_cflag |
| 469 | |= CS8; /* character size 8 bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | /* |
| 472 | * Force low_latency on; otherwise the pushes are scheduled; |
| 473 | * this is bad as it opens up the possibility of dropping bytes |
| 474 | * on the floor. We don't want to drop bytes on the floor. :) |
| 475 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame^] | 476 | tty->low_latency = 1; |
| 477 | tty_encode_baud_rate(tty, 115200, 115200); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | |
| 481 | static int __init empeg_init (void) |
| 482 | { |
| 483 | struct urb *urb; |
| 484 | int i, retval; |
| 485 | |
| 486 | /* create our write urb pool and transfer buffers */ |
| 487 | spin_lock_init (&write_urb_pool_lock); |
| 488 | for (i = 0; i < NUM_URBS; ++i) { |
| 489 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 490 | write_urb_pool[i] = urb; |
| 491 | if (urb == NULL) { |
| 492 | err("No more urbs???"); |
| 493 | continue; |
| 494 | } |
| 495 | |
| 496 | urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); |
| 497 | if (!urb->transfer_buffer) { |
| 498 | err("%s - out of memory for urb buffers.", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 499 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | continue; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | retval = usb_serial_register(&empeg_device); |
| 505 | if (retval) |
| 506 | goto failed_usb_serial_register; |
| 507 | retval = usb_register(&empeg_driver); |
| 508 | if (retval) |
| 509 | goto failed_usb_register; |
| 510 | |
| 511 | info(DRIVER_VERSION ":" DRIVER_DESC); |
| 512 | |
| 513 | return 0; |
| 514 | failed_usb_register: |
| 515 | usb_serial_deregister(&empeg_device); |
| 516 | failed_usb_serial_register: |
| 517 | for (i = 0; i < NUM_URBS; ++i) { |
| 518 | if (write_urb_pool[i]) { |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 519 | kfree(write_urb_pool[i]->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | usb_free_urb(write_urb_pool[i]); |
| 521 | } |
| 522 | } |
| 523 | return retval; |
| 524 | } |
| 525 | |
| 526 | |
| 527 | static void __exit empeg_exit (void) |
| 528 | { |
| 529 | int i; |
| 530 | unsigned long flags; |
| 531 | |
| 532 | usb_deregister(&empeg_driver); |
| 533 | usb_serial_deregister (&empeg_device); |
| 534 | |
| 535 | spin_lock_irqsave (&write_urb_pool_lock, flags); |
| 536 | |
| 537 | for (i = 0; i < NUM_URBS; ++i) { |
| 538 | if (write_urb_pool[i]) { |
| 539 | /* FIXME - uncomment the following usb_kill_urb call when |
| 540 | * the host controllers get fixed to set urb->dev = NULL after |
| 541 | * the urb is finished. Otherwise this call oopses. */ |
| 542 | /* usb_kill_urb(write_urb_pool[i]); */ |
Jesper Juhl | 1bc3c9e | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 543 | kfree(write_urb_pool[i]->transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | usb_free_urb (write_urb_pool[i]); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | spin_unlock_irqrestore (&write_urb_pool_lock, flags); |
| 549 | } |
| 550 | |
| 551 | |
| 552 | module_init(empeg_init); |
| 553 | module_exit(empeg_exit); |
| 554 | |
| 555 | MODULE_AUTHOR( DRIVER_AUTHOR ); |
| 556 | MODULE_DESCRIPTION( DRIVER_DESC ); |
| 557 | MODULE_LICENSE("GPL"); |
| 558 | |
| 559 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 560 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |