Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: empeg: reimplement using generic framework

Kill custom read and write implementations (static 16*4k write-urb pool
shared among all ports in system).

Also remove old changelog entries in header (code is now gone, and
these entries can still be retrieved through git).

Compile-only tested.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
695aaae6 56a1df46

+13 -388
+13 -388
drivers/usb/serial/empeg.c
··· 13 13 * 14 14 * See Documentation/usb/usb-serial.txt for more information on using this 15 15 * driver 16 - * 17 - * (07/16/2001) gb 18 - * remove unused code in empeg_close() (thanks to Oliver Neukum for 19 - * pointing this out) and rewrote empeg_set_termios(). 20 - * 21 - * (05/30/2001) gkh 22 - * switched from using spinlock to a semaphore, which fixes lots of 23 - * problems. 24 - * 25 - * (04/08/2001) gb 26 - * Identify version on module load. 27 - * 28 - * (01/22/2001) gb 29 - * Added write_room() and chars_in_buffer() support. 30 - * 31 - * (12/21/2000) gb 32 - * Moved termio stuff inside the port->active check. 33 - * Moved MOD_DEC_USE_COUNT to end of empeg_close(). 34 - * 35 - * (12/03/2000) gb 36 - * Added tty->ldisc.set_termios(port, tty, NULL) to empeg_open(). 37 - * This notifies the tty driver that the termios have changed. 38 - * 39 - * (11/13/2000) gb 40 - * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to 41 - * empeg_open() (It only needs to be set once - Doh!) 42 - * 43 - * (11/11/2000) gb 44 - * Updated to work with id_table structure. 45 - * 46 - * (11/04/2000) gb 47 - * Forked this from visor.c, and hacked it up to work with an 48 - * Empeg ltd. empeg-car player. Constructive criticism welcomed. 49 - * I would like to say, 'Thank You' to Greg Kroah-Hartman for the 50 - * use of his code, and for his guidance, advice and patience. :) 51 - * A 'Thank You' is in order for John Ripley of Empeg ltd for his 52 - * advice, and patience too. 53 - * 54 16 */ 55 17 56 18 #include <linux/kernel.h> ··· 33 71 /* 34 72 * Version Information 35 73 */ 36 - #define DRIVER_VERSION "v1.2" 74 + #define DRIVER_VERSION "v1.3" 37 75 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>" 38 76 #define DRIVER_DESC "USB Empeg Mark I/II Driver" 39 77 ··· 41 79 #define EMPEG_PRODUCT_ID 0x0001 42 80 43 81 /* function prototypes for an empeg-car player */ 44 - static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port); 45 - static void empeg_close(struct usb_serial_port *port); 46 - static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, 47 - const unsigned char *buf, 48 - int count); 49 - static int empeg_write_room(struct tty_struct *tty); 50 - static int empeg_chars_in_buffer(struct tty_struct *tty); 51 - static void empeg_throttle(struct tty_struct *tty); 52 - static void empeg_unthrottle(struct tty_struct *tty); 53 82 static int empeg_startup(struct usb_serial *serial); 54 83 static void empeg_init_termios(struct tty_struct *tty); 55 - static void empeg_write_bulk_callback(struct urb *urb); 56 - static void empeg_read_bulk_callback(struct urb *urb); 57 84 58 85 static const struct usb_device_id id_table[] = { 59 86 { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, ··· 56 105 .probe = usb_serial_probe, 57 106 .disconnect = usb_serial_disconnect, 58 107 .id_table = id_table, 59 - .no_dynamic_id = 1, 108 + .no_dynamic_id = 1, 60 109 }; 61 110 62 111 static struct usb_serial_driver empeg_device = { ··· 65 114 .name = "empeg", 66 115 }, 67 116 .id_table = id_table, 68 - .usb_driver = &empeg_driver, 117 + .usb_driver = &empeg_driver, 69 118 .num_ports = 1, 70 - .open = empeg_open, 71 - .close = empeg_close, 72 - .throttle = empeg_throttle, 73 - .unthrottle = empeg_unthrottle, 119 + .bulk_out_size = 256, 120 + .throttle = usb_serial_generic_throttle, 121 + .unthrottle = usb_serial_generic_unthrottle, 74 122 .attach = empeg_startup, 75 123 .init_termios = empeg_init_termios, 76 - .write = empeg_write, 77 - .write_room = empeg_write_room, 78 - .chars_in_buffer = empeg_chars_in_buffer, 79 - .write_bulk_callback = empeg_write_bulk_callback, 80 - .read_bulk_callback = empeg_read_bulk_callback, 81 124 }; 82 125 83 - #define NUM_URBS 16 84 - #define URB_TRANSFER_BUFFER_SIZE 4096 85 - 86 - static struct urb *write_urb_pool[NUM_URBS]; 87 - static spinlock_t write_urb_pool_lock; 88 - static int bytes_in; 89 - static int bytes_out; 90 - 91 - /****************************************************************************** 92 - * Empeg specific driver functions 93 - ******************************************************************************/ 94 - static int empeg_open(struct tty_struct *tty,struct usb_serial_port *port) 95 - { 96 - struct usb_serial *serial = port->serial; 97 - int result = 0; 98 - 99 - dbg("%s - port %d", __func__, port->number); 100 - 101 - bytes_in = 0; 102 - bytes_out = 0; 103 - 104 - /* Start reading from the device */ 105 - usb_fill_bulk_urb( 106 - port->read_urb, 107 - serial->dev, 108 - usb_rcvbulkpipe(serial->dev, 109 - port->bulk_in_endpointAddress), 110 - port->read_urb->transfer_buffer, 111 - port->read_urb->transfer_buffer_length, 112 - empeg_read_bulk_callback, 113 - port); 114 - 115 - result = usb_submit_urb(port->read_urb, GFP_KERNEL); 116 - 117 - if (result) 118 - dev_err(&port->dev, 119 - "%s - failed submitting read urb, error %d\n", 120 - __func__, result); 121 - 122 - return result; 123 - } 124 - 125 - 126 - static void empeg_close(struct usb_serial_port *port) 127 - { 128 - dbg("%s - port %d", __func__, port->number); 129 - 130 - /* shutdown our bulk read */ 131 - usb_kill_urb(port->read_urb); 132 - /* Uncomment the following line if you want to see some statistics in your syslog */ 133 - /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */ 134 - } 135 - 136 - 137 - static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, 138 - const unsigned char *buf, int count) 139 - { 140 - struct usb_serial *serial = port->serial; 141 - struct urb *urb; 142 - const unsigned char *current_position = buf; 143 - unsigned long flags; 144 - int status; 145 - int i; 146 - int bytes_sent = 0; 147 - int transfer_size; 148 - 149 - dbg("%s - port %d", __func__, port->number); 150 - 151 - while (count > 0) { 152 - /* try to find a free urb in our list of them */ 153 - urb = NULL; 154 - 155 - spin_lock_irqsave(&write_urb_pool_lock, flags); 156 - 157 - for (i = 0; i < NUM_URBS; ++i) { 158 - if (write_urb_pool[i]->status != -EINPROGRESS) { 159 - urb = write_urb_pool[i]; 160 - break; 161 - } 162 - } 163 - 164 - spin_unlock_irqrestore(&write_urb_pool_lock, flags); 165 - 166 - if (urb == NULL) { 167 - dbg("%s - no more free urbs", __func__); 168 - goto exit; 169 - } 170 - 171 - if (urb->transfer_buffer == NULL) { 172 - urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 173 - if (urb->transfer_buffer == NULL) { 174 - dev_err(&port->dev, 175 - "%s no more kernel memory...\n", 176 - __func__); 177 - goto exit; 178 - } 179 - } 180 - 181 - transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); 182 - 183 - memcpy(urb->transfer_buffer, current_position, transfer_size); 184 - 185 - usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer); 186 - 187 - /* build up our urb */ 188 - usb_fill_bulk_urb( 189 - urb, 190 - serial->dev, 191 - usb_sndbulkpipe(serial->dev, 192 - port->bulk_out_endpointAddress), 193 - urb->transfer_buffer, 194 - transfer_size, 195 - empeg_write_bulk_callback, 196 - port); 197 - 198 - /* send it down the pipe */ 199 - status = usb_submit_urb(urb, GFP_ATOMIC); 200 - if (status) { 201 - dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status); 202 - bytes_sent = status; 203 - break; 204 - } 205 - 206 - current_position += transfer_size; 207 - bytes_sent += transfer_size; 208 - count -= transfer_size; 209 - bytes_out += transfer_size; 210 - 211 - } 212 - exit: 213 - return bytes_sent; 214 - } 215 - 216 - 217 - static int empeg_write_room(struct tty_struct *tty) 218 - { 219 - struct usb_serial_port *port = tty->driver_data; 220 - unsigned long flags; 221 - int i; 222 - int room = 0; 223 - 224 - dbg("%s - port %d", __func__, port->number); 225 - 226 - spin_lock_irqsave(&write_urb_pool_lock, flags); 227 - /* tally up the number of bytes available */ 228 - for (i = 0; i < NUM_URBS; ++i) { 229 - if (write_urb_pool[i]->status != -EINPROGRESS) 230 - room += URB_TRANSFER_BUFFER_SIZE; 231 - } 232 - spin_unlock_irqrestore(&write_urb_pool_lock, flags); 233 - dbg("%s - returns %d", __func__, room); 234 - return room; 235 - 236 - } 237 - 238 - 239 - static int empeg_chars_in_buffer(struct tty_struct *tty) 240 - { 241 - struct usb_serial_port *port = tty->driver_data; 242 - unsigned long flags; 243 - int i; 244 - int chars = 0; 245 - 246 - dbg("%s - port %d", __func__, port->number); 247 - 248 - spin_lock_irqsave(&write_urb_pool_lock, flags); 249 - 250 - /* tally up the number of bytes waiting */ 251 - for (i = 0; i < NUM_URBS; ++i) { 252 - if (write_urb_pool[i]->status == -EINPROGRESS) 253 - chars += URB_TRANSFER_BUFFER_SIZE; 254 - } 255 - 256 - spin_unlock_irqrestore(&write_urb_pool_lock, flags); 257 - dbg("%s - returns %d", __func__, chars); 258 - return chars; 259 - } 260 - 261 - 262 - static void empeg_write_bulk_callback(struct urb *urb) 263 - { 264 - struct usb_serial_port *port = urb->context; 265 - int status = urb->status; 266 - 267 - dbg("%s - port %d", __func__, port->number); 268 - 269 - if (status) { 270 - dbg("%s - nonzero write bulk status received: %d", 271 - __func__, status); 272 - return; 273 - } 274 - 275 - usb_serial_port_softint(port); 276 - } 277 - 278 - 279 - static void empeg_read_bulk_callback(struct urb *urb) 280 - { 281 - struct usb_serial_port *port = urb->context; 282 - struct tty_struct *tty; 283 - unsigned char *data = urb->transfer_buffer; 284 - int result; 285 - int status = urb->status; 286 - 287 - dbg("%s - port %d", __func__, port->number); 288 - 289 - if (status) { 290 - dbg("%s - nonzero read bulk status received: %d", 291 - __func__, status); 292 - return; 293 - } 294 - 295 - usb_serial_debug_data(debug, &port->dev, __func__, 296 - urb->actual_length, data); 297 - tty = tty_port_tty_get(&port->port); 298 - 299 - if (urb->actual_length) { 300 - tty_insert_flip_string(tty, data, urb->actual_length); 301 - tty_flip_buffer_push(tty); 302 - bytes_in += urb->actual_length; 303 - } 304 - tty_kref_put(tty); 305 - 306 - /* Continue trying to always read */ 307 - usb_fill_bulk_urb( 308 - port->read_urb, 309 - port->serial->dev, 310 - usb_rcvbulkpipe(port->serial->dev, 311 - port->bulk_in_endpointAddress), 312 - port->read_urb->transfer_buffer, 313 - port->read_urb->transfer_buffer_length, 314 - empeg_read_bulk_callback, 315 - port); 316 - 317 - result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 318 - 319 - if (result) 320 - dev_err(&urb->dev->dev, 321 - "%s - failed resubmitting read urb, error %d\n", 322 - __func__, result); 323 - 324 - return; 325 - 326 - } 327 - 328 - 329 - static void empeg_throttle(struct tty_struct *tty) 330 - { 331 - struct usb_serial_port *port = tty->driver_data; 332 - dbg("%s - port %d", __func__, port->number); 333 - usb_kill_urb(port->read_urb); 334 - } 335 - 336 - 337 - static void empeg_unthrottle(struct tty_struct *tty) 338 - { 339 - struct usb_serial_port *port = tty->driver_data; 340 - int result; 341 - dbg("%s - port %d", __func__, port->number); 342 - 343 - port->read_urb->dev = port->serial->dev; 344 - result = usb_submit_urb(port->read_urb, GFP_KERNEL); 345 - if (result) 346 - dev_err(&port->dev, 347 - "%s - failed submitting read urb, error %d\n", 348 - __func__, result); 349 - } 350 - 351 - 352 - static int empeg_startup(struct usb_serial *serial) 126 + static int empeg_startup(struct usb_serial *serial) 353 127 { 354 128 int r; 355 129 ··· 90 414 91 415 /* continue on with initialization */ 92 416 return r; 93 - 94 417 } 95 - 96 418 97 419 static void empeg_init_termios(struct tty_struct *tty) 98 420 { ··· 136 462 tty_encode_baud_rate(tty, 115200, 115200); 137 463 } 138 464 139 - 140 465 static int __init empeg_init(void) 141 466 { 142 - struct urb *urb; 143 - int i, retval; 144 - 145 - /* create our write urb pool and transfer buffers */ 146 - spin_lock_init(&write_urb_pool_lock); 147 - for (i = 0; i < NUM_URBS; ++i) { 148 - urb = usb_alloc_urb(0, GFP_KERNEL); 149 - write_urb_pool[i] = urb; 150 - if (urb == NULL) { 151 - printk(KERN_ERR "empeg: No more urbs???\n"); 152 - continue; 153 - } 154 - 155 - urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 156 - GFP_KERNEL); 157 - if (!urb->transfer_buffer) { 158 - printk(KERN_ERR "empeg: %s - out of memory for urb " 159 - "buffers.", __func__); 160 - continue; 161 - } 162 - } 467 + int retval; 163 468 164 469 retval = usb_serial_register(&empeg_device); 165 470 if (retval) 166 - goto failed_usb_serial_register; 471 + return retval; 167 472 retval = usb_register(&empeg_driver); 168 - if (retval) 169 - goto failed_usb_register; 170 - 473 + if (retval) { 474 + usb_serial_deregister(&empeg_device); 475 + return retval; 476 + } 171 477 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 172 478 DRIVER_DESC "\n"); 173 479 174 480 return 0; 175 - failed_usb_register: 176 - usb_serial_deregister(&empeg_device); 177 - failed_usb_serial_register: 178 - for (i = 0; i < NUM_URBS; ++i) { 179 - if (write_urb_pool[i]) { 180 - kfree(write_urb_pool[i]->transfer_buffer); 181 - usb_free_urb(write_urb_pool[i]); 182 - } 183 - } 184 - return retval; 185 481 } 186 - 187 482 188 483 static void __exit empeg_exit(void) 189 484 { 190 - int i; 191 - unsigned long flags; 192 - 193 485 usb_deregister(&empeg_driver); 194 486 usb_serial_deregister(&empeg_device); 195 - 196 - spin_lock_irqsave(&write_urb_pool_lock, flags); 197 - 198 - for (i = 0; i < NUM_URBS; ++i) { 199 - if (write_urb_pool[i]) { 200 - /* FIXME - uncomment the following usb_kill_urb call 201 - * when the host controllers get fixed to set urb->dev 202 - * = NULL after the urb is finished. Otherwise this 203 - * call oopses. */ 204 - /* usb_kill_urb(write_urb_pool[i]); */ 205 - kfree(write_urb_pool[i]->transfer_buffer); 206 - usb_free_urb(write_urb_pool[i]); 207 - } 208 - } 209 - spin_unlock_irqrestore(&write_urb_pool_lock, flags); 210 487 } 211 488 212 489