11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * USB Empeg empeg-car player driver 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Copyright (C) 2000, 2001 51da177e4SLinus Torvalds * Gary Brubaker (xavyer@ix.netcom.com) 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Copyright (C) 1999 - 2001 81da177e4SLinus Torvalds * Greg Kroah-Hartman (greg@kroah.com) 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 111da177e4SLinus Torvalds * it under the terms of the GNU General Public License, as published by 121da177e4SLinus Torvalds * the Free Software Foundation, version 2. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds * See Documentation/usb/usb-serial.txt for more information on using this driver 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * (07/16/2001) gb 171da177e4SLinus Torvalds * remove unused code in empeg_close() (thanks to Oliver Neukum for pointing this 181da177e4SLinus Torvalds * out) and rewrote empeg_set_termios(). 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * (05/30/2001) gkh 211da177e4SLinus Torvalds * switched from using spinlock to a semaphore, which fixes lots of problems. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * (04/08/2001) gb 241da177e4SLinus Torvalds * Identify version on module load. 251da177e4SLinus Torvalds * 261da177e4SLinus Torvalds * (01/22/2001) gb 271da177e4SLinus Torvalds * Added write_room() and chars_in_buffer() support. 281da177e4SLinus Torvalds * 291da177e4SLinus Torvalds * (12/21/2000) gb 301da177e4SLinus Torvalds * Moved termio stuff inside the port->active check. 311da177e4SLinus Torvalds * Moved MOD_DEC_USE_COUNT to end of empeg_close(). 321da177e4SLinus Torvalds * 331da177e4SLinus Torvalds * (12/03/2000) gb 341da177e4SLinus Torvalds * Added port->tty->ldisc.set_termios(port->tty, NULL) to empeg_open() 351da177e4SLinus Torvalds * This notifies the tty driver that the termios have changed. 361da177e4SLinus Torvalds * 371da177e4SLinus Torvalds * (11/13/2000) gb 381da177e4SLinus Torvalds * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to empeg_open() 391da177e4SLinus Torvalds * (It only needs to be set once - Doh!) 401da177e4SLinus Torvalds * 411da177e4SLinus Torvalds * (11/11/2000) gb 421da177e4SLinus Torvalds * Updated to work with id_table structure. 431da177e4SLinus Torvalds * 441da177e4SLinus Torvalds * (11/04/2000) gb 451da177e4SLinus Torvalds * Forked this from visor.c, and hacked it up to work with an 461da177e4SLinus Torvalds * Empeg ltd. empeg-car player. Constructive criticism welcomed. 471da177e4SLinus Torvalds * I would like to say, 'Thank You' to Greg Kroah-Hartman for the 481da177e4SLinus Torvalds * use of his code, and for his guidance, advice and patience. :) 491da177e4SLinus Torvalds * A 'Thank You' is in order for John Ripley of Empeg ltd for his 501da177e4SLinus Torvalds * advice, and patience too. 511da177e4SLinus Torvalds * 521da177e4SLinus Torvalds */ 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds #include <linux/kernel.h> 551da177e4SLinus Torvalds #include <linux/errno.h> 561da177e4SLinus Torvalds #include <linux/init.h> 571da177e4SLinus Torvalds #include <linux/slab.h> 581da177e4SLinus Torvalds #include <linux/tty.h> 591da177e4SLinus Torvalds #include <linux/tty_driver.h> 601da177e4SLinus Torvalds #include <linux/tty_flip.h> 611da177e4SLinus Torvalds #include <linux/module.h> 621da177e4SLinus Torvalds #include <linux/spinlock.h> 631da177e4SLinus Torvalds #include <asm/uaccess.h> 641da177e4SLinus Torvalds #include <linux/usb.h> 65a969888cSGreg Kroah-Hartman #include <linux/usb/serial.h> 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds static int debug; 681da177e4SLinus Torvalds 691da177e4SLinus Torvalds /* 701da177e4SLinus Torvalds * Version Information 711da177e4SLinus Torvalds */ 721da177e4SLinus Torvalds #define DRIVER_VERSION "v1.2" 731da177e4SLinus Torvalds #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Gary Brubaker <xavyer@ix.netcom.com>" 741da177e4SLinus Torvalds #define DRIVER_DESC "USB Empeg Mark I/II Driver" 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds #define EMPEG_VENDOR_ID 0x084f 771da177e4SLinus Torvalds #define EMPEG_PRODUCT_ID 0x0001 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /* function prototypes for an empeg-car player */ 801da177e4SLinus Torvalds static int empeg_open (struct usb_serial_port *port, struct file *filp); 811da177e4SLinus Torvalds static void empeg_close (struct usb_serial_port *port, struct file *filp); 821da177e4SLinus Torvalds static int empeg_write (struct usb_serial_port *port, 831da177e4SLinus Torvalds const unsigned char *buf, 841da177e4SLinus Torvalds int count); 851da177e4SLinus Torvalds static int empeg_write_room (struct usb_serial_port *port); 861da177e4SLinus Torvalds static int empeg_chars_in_buffer (struct usb_serial_port *port); 871da177e4SLinus Torvalds static void empeg_throttle (struct usb_serial_port *port); 881da177e4SLinus Torvalds static void empeg_unthrottle (struct usb_serial_port *port); 891da177e4SLinus Torvalds static int empeg_startup (struct usb_serial *serial); 901da177e4SLinus Torvalds static void empeg_shutdown (struct usb_serial *serial); 911da177e4SLinus Torvalds static int empeg_ioctl (struct usb_serial_port *port, 921da177e4SLinus Torvalds struct file * file, 931da177e4SLinus Torvalds unsigned int cmd, 941da177e4SLinus Torvalds unsigned long arg); 95606d099cSAlan Cox static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios); 967d12e780SDavid Howells static void empeg_write_bulk_callback (struct urb *urb); 977d12e780SDavid Howells static void empeg_read_bulk_callback (struct urb *urb); 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds static struct usb_device_id id_table [] = { 1001da177e4SLinus Torvalds { USB_DEVICE(EMPEG_VENDOR_ID, EMPEG_PRODUCT_ID) }, 1011da177e4SLinus Torvalds { } /* Terminating entry */ 1021da177e4SLinus Torvalds }; 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds MODULE_DEVICE_TABLE (usb, id_table); 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds static struct usb_driver empeg_driver = { 1071da177e4SLinus Torvalds .name = "empeg", 1081da177e4SLinus Torvalds .probe = usb_serial_probe, 1091da177e4SLinus Torvalds .disconnect = usb_serial_disconnect, 1101da177e4SLinus Torvalds .id_table = id_table, 111ba9dc657SGreg Kroah-Hartman .no_dynamic_id = 1, 1121da177e4SLinus Torvalds }; 1131da177e4SLinus Torvalds 114ea65370dSGreg Kroah-Hartman static struct usb_serial_driver empeg_device = { 11518fcac35SGreg Kroah-Hartman .driver = { 1161da177e4SLinus Torvalds .owner = THIS_MODULE, 117269bda1cSGreg Kroah-Hartman .name = "empeg", 11818fcac35SGreg Kroah-Hartman }, 1191da177e4SLinus Torvalds .id_table = id_table, 120d9b1b787SJohannes Hölzl .usb_driver = &empeg_driver, 1211da177e4SLinus Torvalds .num_ports = 1, 1221da177e4SLinus Torvalds .open = empeg_open, 1231da177e4SLinus Torvalds .close = empeg_close, 1241da177e4SLinus Torvalds .throttle = empeg_throttle, 1251da177e4SLinus Torvalds .unthrottle = empeg_unthrottle, 1261da177e4SLinus Torvalds .attach = empeg_startup, 1271da177e4SLinus Torvalds .shutdown = empeg_shutdown, 1281da177e4SLinus Torvalds .ioctl = empeg_ioctl, 1291da177e4SLinus Torvalds .set_termios = empeg_set_termios, 1301da177e4SLinus Torvalds .write = empeg_write, 1311da177e4SLinus Torvalds .write_room = empeg_write_room, 1321da177e4SLinus Torvalds .chars_in_buffer = empeg_chars_in_buffer, 1331da177e4SLinus Torvalds .write_bulk_callback = empeg_write_bulk_callback, 1341da177e4SLinus Torvalds .read_bulk_callback = empeg_read_bulk_callback, 1351da177e4SLinus Torvalds }; 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds #define NUM_URBS 16 1381da177e4SLinus Torvalds #define URB_TRANSFER_BUFFER_SIZE 4096 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds static struct urb *write_urb_pool[NUM_URBS]; 1411da177e4SLinus Torvalds static spinlock_t write_urb_pool_lock; 1421da177e4SLinus Torvalds static int bytes_in; 1431da177e4SLinus Torvalds static int bytes_out; 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds /****************************************************************************** 1461da177e4SLinus Torvalds * Empeg specific driver functions 1471da177e4SLinus Torvalds ******************************************************************************/ 1481da177e4SLinus Torvalds static int empeg_open (struct usb_serial_port *port, struct file *filp) 1491da177e4SLinus Torvalds { 1501da177e4SLinus Torvalds struct usb_serial *serial = port->serial; 1511da177e4SLinus Torvalds int result = 0; 1521da177e4SLinus Torvalds 153*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 1541da177e4SLinus Torvalds 1551da177e4SLinus Torvalds /* Force default termio settings */ 1561da177e4SLinus Torvalds empeg_set_termios (port, NULL) ; 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds bytes_in = 0; 1591da177e4SLinus Torvalds bytes_out = 0; 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds /* Start reading from the device */ 1621da177e4SLinus Torvalds usb_fill_bulk_urb( 1631da177e4SLinus Torvalds port->read_urb, 1641da177e4SLinus Torvalds serial->dev, 1651da177e4SLinus Torvalds usb_rcvbulkpipe(serial->dev, 1661da177e4SLinus Torvalds port->bulk_in_endpointAddress), 1671da177e4SLinus Torvalds port->read_urb->transfer_buffer, 1681da177e4SLinus Torvalds port->read_urb->transfer_buffer_length, 1691da177e4SLinus Torvalds empeg_read_bulk_callback, 1701da177e4SLinus Torvalds port); 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds result = usb_submit_urb(port->read_urb, GFP_KERNEL); 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds if (result) 175*441b62c1SHarvey Harrison dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds return result; 1781da177e4SLinus Torvalds } 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds static void empeg_close (struct usb_serial_port *port, struct file * filp) 1821da177e4SLinus Torvalds { 183*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds /* shutdown our bulk read */ 1861da177e4SLinus Torvalds usb_kill_urb(port->read_urb); 1871da177e4SLinus Torvalds /* Uncomment the following line if you want to see some statistics in your syslog */ 1881da177e4SLinus Torvalds /* dev_info (&port->dev, "Bytes In = %d Bytes Out = %d\n", bytes_in, bytes_out); */ 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds static int empeg_write (struct usb_serial_port *port, const unsigned char *buf, int count) 1931da177e4SLinus Torvalds { 1941da177e4SLinus Torvalds struct usb_serial *serial = port->serial; 1951da177e4SLinus Torvalds struct urb *urb; 1961da177e4SLinus Torvalds const unsigned char *current_position = buf; 1971da177e4SLinus Torvalds unsigned long flags; 1981da177e4SLinus Torvalds int status; 1991da177e4SLinus Torvalds int i; 2001da177e4SLinus Torvalds int bytes_sent = 0; 2011da177e4SLinus Torvalds int transfer_size; 2021da177e4SLinus Torvalds 203*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds while (count > 0) { 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds /* try to find a free urb in our list of them */ 2081da177e4SLinus Torvalds urb = NULL; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds spin_lock_irqsave (&write_urb_pool_lock, flags); 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds for (i = 0; i < NUM_URBS; ++i) { 2131da177e4SLinus Torvalds if (write_urb_pool[i]->status != -EINPROGRESS) { 2141da177e4SLinus Torvalds urb = write_urb_pool[i]; 2151da177e4SLinus Torvalds break; 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds } 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds spin_unlock_irqrestore (&write_urb_pool_lock, flags); 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds if (urb == NULL) { 222*441b62c1SHarvey Harrison dbg("%s - no more free urbs", __func__); 2231da177e4SLinus Torvalds goto exit; 2241da177e4SLinus Torvalds } 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds if (urb->transfer_buffer == NULL) { 2271da177e4SLinus Torvalds urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); 2281da177e4SLinus Torvalds if (urb->transfer_buffer == NULL) { 229*441b62c1SHarvey Harrison dev_err(&port->dev, "%s no more kernel memory...\n", __func__); 2301da177e4SLinus Torvalds goto exit; 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds } 2331da177e4SLinus Torvalds 2341da177e4SLinus Torvalds transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE); 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds memcpy (urb->transfer_buffer, current_position, transfer_size); 2371da177e4SLinus Torvalds 238*441b62c1SHarvey Harrison usb_serial_debug_data(debug, &port->dev, __func__, transfer_size, urb->transfer_buffer); 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds /* build up our urb */ 2411da177e4SLinus Torvalds usb_fill_bulk_urb ( 2421da177e4SLinus Torvalds urb, 2431da177e4SLinus Torvalds serial->dev, 2441da177e4SLinus Torvalds usb_sndbulkpipe(serial->dev, 2451da177e4SLinus Torvalds port->bulk_out_endpointAddress), 2461da177e4SLinus Torvalds urb->transfer_buffer, 2471da177e4SLinus Torvalds transfer_size, 2481da177e4SLinus Torvalds empeg_write_bulk_callback, 2491da177e4SLinus Torvalds port); 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds /* send it down the pipe */ 2521da177e4SLinus Torvalds status = usb_submit_urb(urb, GFP_ATOMIC); 2531da177e4SLinus Torvalds if (status) { 254*441b62c1SHarvey Harrison dev_err(&port->dev, "%s - usb_submit_urb(write bulk) failed with status = %d\n", __func__, status); 2551da177e4SLinus Torvalds bytes_sent = status; 2561da177e4SLinus Torvalds break; 2571da177e4SLinus Torvalds } 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds current_position += transfer_size; 2601da177e4SLinus Torvalds bytes_sent += transfer_size; 2611da177e4SLinus Torvalds count -= transfer_size; 2621da177e4SLinus Torvalds bytes_out += transfer_size; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds } 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds exit: 2671da177e4SLinus Torvalds return bytes_sent; 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds static int empeg_write_room (struct usb_serial_port *port) 2731da177e4SLinus Torvalds { 2741da177e4SLinus Torvalds unsigned long flags; 2751da177e4SLinus Torvalds int i; 2761da177e4SLinus Torvalds int room = 0; 2771da177e4SLinus Torvalds 278*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds spin_lock_irqsave (&write_urb_pool_lock, flags); 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvalds /* tally up the number of bytes available */ 2831da177e4SLinus Torvalds for (i = 0; i < NUM_URBS; ++i) { 2841da177e4SLinus Torvalds if (write_urb_pool[i]->status != -EINPROGRESS) { 2851da177e4SLinus Torvalds room += URB_TRANSFER_BUFFER_SIZE; 2861da177e4SLinus Torvalds } 2871da177e4SLinus Torvalds } 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds spin_unlock_irqrestore (&write_urb_pool_lock, flags); 2901da177e4SLinus Torvalds 291*441b62c1SHarvey Harrison dbg("%s - returns %d", __func__, room); 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvalds return (room); 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds } 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds static int empeg_chars_in_buffer (struct usb_serial_port *port) 2991da177e4SLinus Torvalds { 3001da177e4SLinus Torvalds unsigned long flags; 3011da177e4SLinus Torvalds int i; 3021da177e4SLinus Torvalds int chars = 0; 3031da177e4SLinus Torvalds 304*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds spin_lock_irqsave (&write_urb_pool_lock, flags); 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds /* tally up the number of bytes waiting */ 3091da177e4SLinus Torvalds for (i = 0; i < NUM_URBS; ++i) { 3101da177e4SLinus Torvalds if (write_urb_pool[i]->status == -EINPROGRESS) { 3111da177e4SLinus Torvalds chars += URB_TRANSFER_BUFFER_SIZE; 3121da177e4SLinus Torvalds } 3131da177e4SLinus Torvalds } 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds spin_unlock_irqrestore (&write_urb_pool_lock, flags); 3161da177e4SLinus Torvalds 317*441b62c1SHarvey Harrison dbg("%s - returns %d", __func__, chars); 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds return (chars); 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds } 3221da177e4SLinus Torvalds 3231da177e4SLinus Torvalds 3247d12e780SDavid Howells static void empeg_write_bulk_callback (struct urb *urb) 3251da177e4SLinus Torvalds { 326335202f4SGreg Kroah-Hartman struct usb_serial_port *port = urb->context; 327335202f4SGreg Kroah-Hartman int status = urb->status; 3281da177e4SLinus Torvalds 329*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 3301da177e4SLinus Torvalds 331335202f4SGreg Kroah-Hartman if (status) { 332335202f4SGreg Kroah-Hartman dbg("%s - nonzero write bulk status received: %d", 333*441b62c1SHarvey Harrison __func__, status); 3341da177e4SLinus Torvalds return; 3351da177e4SLinus Torvalds } 3361da177e4SLinus Torvalds 337cf2c7481SPete Zaitcev usb_serial_port_softint(port); 3381da177e4SLinus Torvalds } 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds 3417d12e780SDavid Howells static void empeg_read_bulk_callback (struct urb *urb) 3421da177e4SLinus Torvalds { 3431da177e4SLinus Torvalds struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 3441da177e4SLinus Torvalds struct tty_struct *tty; 3451da177e4SLinus Torvalds unsigned char *data = urb->transfer_buffer; 3461da177e4SLinus Torvalds int result; 347335202f4SGreg Kroah-Hartman int status = urb->status; 3481da177e4SLinus Torvalds 349*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 3501da177e4SLinus Torvalds 351335202f4SGreg Kroah-Hartman if (status) { 352335202f4SGreg Kroah-Hartman dbg("%s - nonzero read bulk status received: %d", 353*441b62c1SHarvey Harrison __func__, status); 3541da177e4SLinus Torvalds return; 3551da177e4SLinus Torvalds } 3561da177e4SLinus Torvalds 357*441b62c1SHarvey Harrison usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds tty = port->tty; 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds if (urb->actual_length) { 36233f0f88fSAlan Cox tty_buffer_request_room(tty, urb->actual_length); 36333f0f88fSAlan Cox tty_insert_flip_string(tty, data, urb->actual_length); 3641da177e4SLinus Torvalds tty_flip_buffer_push(tty); 3651da177e4SLinus Torvalds bytes_in += urb->actual_length; 3661da177e4SLinus Torvalds } 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds /* Continue trying to always read */ 3691da177e4SLinus Torvalds usb_fill_bulk_urb( 3701da177e4SLinus Torvalds port->read_urb, 3711da177e4SLinus Torvalds port->serial->dev, 3721da177e4SLinus Torvalds usb_rcvbulkpipe(port->serial->dev, 3731da177e4SLinus Torvalds port->bulk_in_endpointAddress), 3741da177e4SLinus Torvalds port->read_urb->transfer_buffer, 3751da177e4SLinus Torvalds port->read_urb->transfer_buffer_length, 3761da177e4SLinus Torvalds empeg_read_bulk_callback, 3771da177e4SLinus Torvalds port); 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvalds if (result) 382*441b62c1SHarvey Harrison dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvalds return; 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds } 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds static void empeg_throttle (struct usb_serial_port *port) 3901da177e4SLinus Torvalds { 391*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 3921da177e4SLinus Torvalds usb_kill_urb(port->read_urb); 3931da177e4SLinus Torvalds } 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds static void empeg_unthrottle (struct usb_serial_port *port) 3971da177e4SLinus Torvalds { 3981da177e4SLinus Torvalds int result; 3991da177e4SLinus Torvalds 400*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 4011da177e4SLinus Torvalds 4021da177e4SLinus Torvalds port->read_urb->dev = port->serial->dev; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds result = usb_submit_urb(port->read_urb, GFP_ATOMIC); 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds if (result) 407*441b62c1SHarvey Harrison dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result); 4081da177e4SLinus Torvalds 4091da177e4SLinus Torvalds return; 4101da177e4SLinus Torvalds } 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds static int empeg_startup (struct usb_serial *serial) 4141da177e4SLinus Torvalds { 4151da177e4SLinus Torvalds int r; 4161da177e4SLinus Torvalds 417*441b62c1SHarvey Harrison dbg("%s", __func__); 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvalds if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 4201da177e4SLinus Torvalds err("active config #%d != 1 ??", 4211da177e4SLinus Torvalds serial->dev->actconfig->desc.bConfigurationValue); 4221da177e4SLinus Torvalds return -ENODEV; 4231da177e4SLinus Torvalds } 424*441b62c1SHarvey Harrison dbg("%s - reset config", __func__); 4251da177e4SLinus Torvalds r = usb_reset_configuration (serial->dev); 4261da177e4SLinus Torvalds 4271da177e4SLinus Torvalds /* continue on with initialization */ 4281da177e4SLinus Torvalds return r; 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds } 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds static void empeg_shutdown (struct usb_serial *serial) 4341da177e4SLinus Torvalds { 435*441b62c1SHarvey Harrison dbg ("%s", __func__); 4361da177e4SLinus Torvalds } 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg) 4401da177e4SLinus Torvalds { 441*441b62c1SHarvey Harrison dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds return -ENOIOCTLCMD; 4441da177e4SLinus Torvalds } 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvalds 447606d099cSAlan Cox static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios) 4481da177e4SLinus Torvalds { 449998e8638SAlan Cox struct ktermios *termios = port->tty->termios; 450*441b62c1SHarvey Harrison dbg("%s - port %d", __func__, port->number); 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds /* 4531da177e4SLinus Torvalds * The empeg-car player wants these particular tty settings. 4541da177e4SLinus Torvalds * You could, for example, change the baud rate, however the 4551da177e4SLinus Torvalds * player only supports 115200 (currently), so there is really 4561da177e4SLinus Torvalds * no point in support for changes to the tty settings. 4571da177e4SLinus Torvalds * (at least for now) 4581da177e4SLinus Torvalds * 4591da177e4SLinus Torvalds * The default requirements for this device are: 4601da177e4SLinus Torvalds */ 461998e8638SAlan Cox termios->c_iflag 4621da177e4SLinus Torvalds &= ~(IGNBRK /* disable ignore break */ 4631da177e4SLinus Torvalds | BRKINT /* disable break causes interrupt */ 4641da177e4SLinus Torvalds | PARMRK /* disable mark parity errors */ 4651da177e4SLinus Torvalds | ISTRIP /* disable clear high bit of input characters */ 4661da177e4SLinus Torvalds | INLCR /* disable translate NL to CR */ 4671da177e4SLinus Torvalds | IGNCR /* disable ignore CR */ 4681da177e4SLinus Torvalds | ICRNL /* disable translate CR to NL */ 4691da177e4SLinus Torvalds | IXON); /* disable enable XON/XOFF flow control */ 4701da177e4SLinus Torvalds 471998e8638SAlan Cox termios->c_oflag 4721da177e4SLinus Torvalds &= ~OPOST; /* disable postprocess output characters */ 4731da177e4SLinus Torvalds 474998e8638SAlan Cox termios->c_lflag 4751da177e4SLinus Torvalds &= ~(ECHO /* disable echo input characters */ 4761da177e4SLinus Torvalds | ECHONL /* disable echo new line */ 4771da177e4SLinus Torvalds | ICANON /* disable erase, kill, werase, and rprnt special characters */ 4781da177e4SLinus Torvalds | ISIG /* disable interrupt, quit, and suspend special characters */ 4791da177e4SLinus Torvalds | IEXTEN); /* disable non-POSIX special characters */ 4801da177e4SLinus Torvalds 481998e8638SAlan Cox termios->c_cflag 4821da177e4SLinus Torvalds &= ~(CSIZE /* no size */ 4831da177e4SLinus Torvalds | PARENB /* disable parity bit */ 4841da177e4SLinus Torvalds | CBAUD); /* clear current baud rate */ 4851da177e4SLinus Torvalds 486998e8638SAlan Cox termios->c_cflag 487998e8638SAlan Cox |= CS8; /* character size 8 bits */ 4881da177e4SLinus Torvalds 4891da177e4SLinus Torvalds /* 4901da177e4SLinus Torvalds * Force low_latency on; otherwise the pushes are scheduled; 4911da177e4SLinus Torvalds * this is bad as it opens up the possibility of dropping bytes 4921da177e4SLinus Torvalds * on the floor. We don't want to drop bytes on the floor. :) 4931da177e4SLinus Torvalds */ 4941da177e4SLinus Torvalds port->tty->low_latency = 1; 495998e8638SAlan Cox tty_encode_baud_rate(port->tty, 115200, 115200); 4961da177e4SLinus Torvalds } 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds static int __init empeg_init (void) 5001da177e4SLinus Torvalds { 5011da177e4SLinus Torvalds struct urb *urb; 5021da177e4SLinus Torvalds int i, retval; 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds /* create our write urb pool and transfer buffers */ 5051da177e4SLinus Torvalds spin_lock_init (&write_urb_pool_lock); 5061da177e4SLinus Torvalds for (i = 0; i < NUM_URBS; ++i) { 5071da177e4SLinus Torvalds urb = usb_alloc_urb(0, GFP_KERNEL); 5081da177e4SLinus Torvalds write_urb_pool[i] = urb; 5091da177e4SLinus Torvalds if (urb == NULL) { 5101da177e4SLinus Torvalds err("No more urbs???"); 5111da177e4SLinus Torvalds continue; 5121da177e4SLinus Torvalds } 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL); 5151da177e4SLinus Torvalds if (!urb->transfer_buffer) { 5161da177e4SLinus Torvalds err("%s - out of memory for urb buffers.", 517*441b62c1SHarvey Harrison __func__); 5181da177e4SLinus Torvalds continue; 5191da177e4SLinus Torvalds } 5201da177e4SLinus Torvalds } 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds retval = usb_serial_register(&empeg_device); 5231da177e4SLinus Torvalds if (retval) 5241da177e4SLinus Torvalds goto failed_usb_serial_register; 5251da177e4SLinus Torvalds retval = usb_register(&empeg_driver); 5261da177e4SLinus Torvalds if (retval) 5271da177e4SLinus Torvalds goto failed_usb_register; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds info(DRIVER_VERSION ":" DRIVER_DESC); 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvalds return 0; 5321da177e4SLinus Torvalds failed_usb_register: 5331da177e4SLinus Torvalds usb_serial_deregister(&empeg_device); 5341da177e4SLinus Torvalds failed_usb_serial_register: 5351da177e4SLinus Torvalds for (i = 0; i < NUM_URBS; ++i) { 5361da177e4SLinus Torvalds if (write_urb_pool[i]) { 5371da177e4SLinus Torvalds kfree(write_urb_pool[i]->transfer_buffer); 5381da177e4SLinus Torvalds usb_free_urb(write_urb_pool[i]); 5391da177e4SLinus Torvalds } 5401da177e4SLinus Torvalds } 5411da177e4SLinus Torvalds return retval; 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds static void __exit empeg_exit (void) 5461da177e4SLinus Torvalds { 5471da177e4SLinus Torvalds int i; 5481da177e4SLinus Torvalds unsigned long flags; 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds usb_deregister(&empeg_driver); 5511da177e4SLinus Torvalds usb_serial_deregister (&empeg_device); 5521da177e4SLinus Torvalds 5531da177e4SLinus Torvalds spin_lock_irqsave (&write_urb_pool_lock, flags); 5541da177e4SLinus Torvalds 5551da177e4SLinus Torvalds for (i = 0; i < NUM_URBS; ++i) { 5561da177e4SLinus Torvalds if (write_urb_pool[i]) { 5571da177e4SLinus Torvalds /* FIXME - uncomment the following usb_kill_urb call when 5581da177e4SLinus Torvalds * the host controllers get fixed to set urb->dev = NULL after 5591da177e4SLinus Torvalds * the urb is finished. Otherwise this call oopses. */ 5601da177e4SLinus Torvalds /* usb_kill_urb(write_urb_pool[i]); */ 5611da177e4SLinus Torvalds kfree(write_urb_pool[i]->transfer_buffer); 5621da177e4SLinus Torvalds usb_free_urb (write_urb_pool[i]); 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds } 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds spin_unlock_irqrestore (&write_urb_pool_lock, flags); 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds module_init(empeg_init); 5711da177e4SLinus Torvalds module_exit(empeg_exit); 5721da177e4SLinus Torvalds 5731da177e4SLinus Torvalds MODULE_AUTHOR( DRIVER_AUTHOR ); 5741da177e4SLinus Torvalds MODULE_DESCRIPTION( DRIVER_DESC ); 5751da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds module_param(debug, bool, S_IRUGO | S_IWUSR); 5781da177e4SLinus Torvalds MODULE_PARM_DESC(debug, "Debug enabled or not"); 579