This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / drivers / usb / serial / io_edgeport.c
index 010160e..87f99a3 100644 (file)
  *     Edgeport/4D8
  *     Edgeport/8i
  *
- * For questions or problems with this driver, contact Inside Out
- * Networks technical support, or Peter Berger <pberger@brimson.com>,
- * or Al Borchers <alborchers@steinerpoint.com>.
- *
  * Version history:
  * 
  * 2003_04_03 al borchers
 /*
  * Version Information
  */
-#define DRIVER_VERSION "v2.7"
+#define DRIVER_VERSION "v2.3"
 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com> and David Iacovelli"
 #define DRIVER_DESC "Edgeport USB Serial Driver"
 
 #define OPEN_TIMEOUT           (5*HZ)          /* 5 seconds */
 #define COMMAND_TIMEOUT                (5*HZ)          /* 5 seconds */
 
+static int debug;
+
 /* receive port state */
 enum RXSTATE {
        EXPECT_HDR1 = 0,        /* Expect header byte 1 */
@@ -331,7 +329,6 @@ struct edgeport_port {
        struct TxFifo           txfifo;                 /* transmit fifo -- size will be maxTxCredits */
        struct urb              *write_urb;             /* write URB for this port */
        char                    write_in_progress;      /* TRUE while a write URB is outstanding */
-       spinlock_t              ep_lock;
 
        __u8                    shadowLCR;              /* last LCR value received */
        __u8                    shadowMCR;              /* last MCR value received */
@@ -373,8 +370,6 @@ struct edgeport_serial {
        __u8                    bulk_in_endpoint;               /* the bulk in endpoint handle */
        unsigned char *         bulk_in_buffer;                 /* the buffer we use for the bulk in endpoint */
        struct urb *            read_urb;                       /* our bulk read urb */
-       int                     read_in_progress;
-       spinlock_t              es_lock;
 
        __u8                    bulk_out_endpoint;              /* the bulk out endpoint handle */
 
@@ -425,11 +420,7 @@ static struct divisor_table_entry divisor_table[] = {
 };
 
 /* local variables */
-static int debug;
-
-static int low_latency = 1;    /* tty low latency flag, on by default */
-
-static int CmdUrbs = 0;                /* Number of outstanding Command Write Urbs */
+static int     CmdUrbs = 0;                                                    /* Number of outstanding Command Write Urbs */
 
 
 /* local function prototypes */
@@ -443,7 +434,7 @@ static void edge_bulk_out_cmd_callback      (struct urb *urb, struct pt_regs *regs);
 /* function prototypes for the usbserial callbacks */
 static int  edge_open                  (struct usb_serial_port *port, struct file *filp);
 static void edge_close                 (struct usb_serial_port *port, struct file *filp);
-static int  edge_write                 (struct usb_serial_port *port, const unsigned char *buf, int count);
+static int  edge_write                 (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
 static int  edge_write_room            (struct usb_serial_port *port);
 static int  edge_chars_in_buffer       (struct usb_serial_port *port);
 static void edge_throttle              (struct usb_serial_port *port);
@@ -468,9 +459,8 @@ static struct usb_driver io_driver = {
 };
 
 /* function prototypes for all of our local functions */
-static void  process_rcvd_data         (struct edgeport_serial *edge_serial, unsigned char *buffer, __u16 bufferLength);
+static int  process_rcvd_data          (struct edgeport_serial *edge_serial, unsigned char *buffer, __u16 bufferLength);
 static void process_rcvd_status                (struct edgeport_serial *edge_serial, __u8 byte2, __u8 byte3);
-static void edge_tty_recv                      (struct device *dev, struct tty_struct *tty, unsigned char *data, int length);
 static void handle_new_msr             (struct edgeport_port *edge_port, __u8 newMsr);
 static void handle_new_lsr             (struct edgeport_port *edge_port, __u8 lsrData, __u8 lsr, __u8 data);
 static int  send_iosp_ext_cmd          (struct edgeport_port *edge_port, __u8 command, __u8 param);
@@ -488,9 +478,13 @@ static void get_manufacturing_desc (struct edgeport_serial *edge_serial);
 static void get_boot_desc              (struct edgeport_serial *edge_serial);
 static void load_application_firmware  (struct edgeport_serial *edge_serial);
 
+
 static void unicode_to_ascii           (char *string, __le16 *unicode, int unicode_size);
 
 
+
+
+
 // ************************************************************************
 // ************************************************************************
 // ************************************************************************
@@ -790,24 +784,20 @@ static void edge_interrupt_callback (struct urb *urb, struct pt_regs *regs)
                if (length > 1) {
                        bytes_avail = data[0] | (data[1] << 8);
                        if (bytes_avail) {
-                               spin_lock(&edge_serial->es_lock);
                                edge_serial->rxBytesAvail += bytes_avail;
-                               dbg("%s - bytes_avail=%d, rxBytesAvail=%d, read_in_progress=%d", __FUNCTION__, bytes_avail, edge_serial->rxBytesAvail, edge_serial->read_in_progress);
+                               dbg("%s - bytes_avail = %d, rxBytesAvail %d", __FUNCTION__, bytes_avail, edge_serial->rxBytesAvail);
 
-                               if (edge_serial->rxBytesAvail > 0 &&
-                                   !edge_serial->read_in_progress) {
-                                       dbg("%s - posting a read", __FUNCTION__);
-                                       edge_serial->read_in_progress = TRUE;
+                               if ((edge_serial->rxBytesAvail > 0) &&
+                                   (edge_serial->read_urb->status != -EINPROGRESS)) {
+                                       dbg(" --- Posting a read");
 
                                        /* we have pending bytes on the bulk in pipe, send a request */
                                        edge_serial->read_urb->dev = edge_serial->serial->dev;
                                        result = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
                                        if (result) {
-                                               dev_err(&edge_serial->serial->dev->dev, "%s - usb_submit_urb(read bulk) failed with result = %d\n", __FUNCTION__, result);
-                                               edge_serial->read_in_progress = FALSE;
+                                               dbg("%s - usb_submit_urb(read bulk) failed with result = %d", __FUNCTION__, result);
                                        }
                                }
-                               spin_unlock(&edge_serial->es_lock);
                        }
                }
                /* grab the txcredits for the ports if available */
@@ -819,14 +809,12 @@ static void edge_interrupt_callback (struct urb *urb, struct pt_regs *regs)
                                port = edge_serial->serial->port[portNumber];
                                edge_port = usb_get_serial_port_data(port);
                                if (edge_port->open) {
-                                       spin_lock(&edge_port->ep_lock);
                                        edge_port->txCredits += txCredits;
-                                       spin_unlock(&edge_port->ep_lock);
                                        dbg("%s - txcredits for port%d = %d", __FUNCTION__, portNumber, edge_port->txCredits);
 
                                        /* tell the tty driver that something has changed */
                                        if (edge_port->port->tty)
-                                               tty_wakeup(edge_port->port->tty);
+                                               wake_up_interruptible(&edge_port->port->tty->write_wait);
 
                                        // Since we have more credit, check if more data can be sent
                                        send_more_port_data(edge_serial, edge_port);
@@ -861,43 +849,34 @@ static void edge_bulk_in_callback (struct urb *urb, struct pt_regs *regs)
 
        if (urb->status) {
                dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
-               edge_serial->read_in_progress = FALSE;
-               return;
-       }
-
-       if (urb->actual_length == 0) {
-               dbg("%s - read bulk callback with no data", __FUNCTION__);
-               edge_serial->read_in_progress = FALSE;
                return;
        }
 
-       raw_data_length = urb->actual_length;
+       if (urb->actual_length) {
+               raw_data_length = urb->actual_length;
 
-       usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, raw_data_length, data);
+               usb_serial_debug_data(debug, &edge_serial->serial->dev->dev, __FUNCTION__, raw_data_length, data);
 
-       spin_lock(&edge_serial->es_lock);
+               /* decrement our rxBytes available by the number that we just got */
+               edge_serial->rxBytesAvail -= raw_data_length;
 
-       /* decrement our rxBytes available by the number that we just got */
-       edge_serial->rxBytesAvail -= raw_data_length;
+               dbg("%s - Received = %d, rxBytesAvail %d", __FUNCTION__, raw_data_length, edge_serial->rxBytesAvail);
 
-       dbg("%s - Received = %d, rxBytesAvail %d", __FUNCTION__, raw_data_length, edge_serial->rxBytesAvail);
+               process_rcvd_data (edge_serial, data, urb->actual_length);
 
-       process_rcvd_data (edge_serial, data, urb->actual_length);
+               /* check to see if there's any more data for us to read */
+               if ((edge_serial->rxBytesAvail > 0) &&
+                   (edge_serial->read_urb->status != -EINPROGRESS)) {
+                       dbg(" --- Posting a read");
 
-       /* check to see if there's any more data for us to read */
-       if (edge_serial->rxBytesAvail > 0) {
-               dbg("%s - posting a read", __FUNCTION__);
-               edge_serial->read_urb->dev = edge_serial->serial->dev;
-               status = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
-               if (status) {
-                       dev_err(&urb->dev->dev, "%s - usb_submit_urb(read bulk) failed, status = %d\n", __FUNCTION__, status);
-                       edge_serial->read_in_progress = FALSE;
+                       /* there is, so resubmit our urb */
+                       edge_serial->read_urb->dev = edge_serial->serial->dev;
+                       status = usb_submit_urb(edge_serial->read_urb, GFP_ATOMIC);
+                       if (status) {
+                               dev_err(&urb->dev->dev, "%s - usb_submit_urb(read bulk) failed, status = %d\n", __FUNCTION__, status);
+                       }
                }
-       } else {
-               edge_serial->read_in_progress = FALSE;
        }
-
-       spin_unlock(&edge_serial->es_lock);
 }
 
 
@@ -967,7 +946,7 @@ static void edge_bulk_out_cmd_callback (struct urb *urb, struct pt_regs *regs)
 
        /* tell the tty driver that something has changed */
        if (tty && edge_port->open)
-               tty_wakeup(tty);
+               wake_up_interruptible(&tty->write_wait);
 
        /* we have completed the command */
        edge_port->commandPending = FALSE;
@@ -998,8 +977,11 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
        if (edge_port == NULL)
                return -ENODEV;
 
+       /* force low_latency on so that our tty_push actually forces the data through, 
+          otherwise it is scheduled, and with high data rates (like with OHCI) data
+          can get lost. */
        if (port->tty)
-               port->tty->low_latency = low_latency;
+               port->tty->low_latency = 1;
 
        /* see if we've set up our endpoint info yet (can't set it up in edge_startup
           as the structures were not set up at that time.) */
@@ -1037,7 +1019,6 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
                                  port0->bulk_in_buffer,
                                  edge_serial->read_urb->transfer_buffer_length,
                                  edge_bulk_in_callback, edge_serial);
-               edge_serial->read_in_progress = FALSE;
 
                /* start interrupt read for this edgeport
                 * this interrupt will continue as long as the edgeport is connected */
@@ -1100,7 +1081,6 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
 
        /* Allocate a URB for the write */
        edge_port->write_urb = usb_alloc_urb (0, GFP_KERNEL);
-       edge_port->write_in_progress = FALSE;
 
        if (!edge_port->write_urb) {
                dbg("%s - no memory", __FUNCTION__);
@@ -1258,7 +1238,7 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
        edge_port->openPending = FALSE;
 
        if (edge_port->write_urb) {
-               usb_kill_urb(edge_port->write_urb);
+               usb_unlink_urb (edge_port->write_urb);
        }
 
        if (edge_port->write_urb) {
@@ -1267,11 +1247,9 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
                        kfree(edge_port->write_urb->transfer_buffer);
                }
                usb_free_urb   (edge_port->write_urb);
-               edge_port->write_urb = NULL;
        }
        if (edge_port->txfifo.fifo) {
                kfree(edge_port->txfifo.fifo);
-               edge_port->txfifo.fifo = NULL;
        }
 
        dbg("%s exited", __FUNCTION__);
@@ -1284,15 +1262,14 @@ static void edge_close (struct usb_serial_port *port, struct file * filp)
  *     If successful, we return the number of bytes written, otherwise we return
  *     a negative error number.
  *****************************************************************************/
-static int edge_write (struct usb_serial_port *port, const unsigned char *data, int count)
+static int edge_write (struct usb_serial_port *port, int from_user, const unsigned char *data, int count)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        struct TxFifo *fifo;
        int copySize;
        int bytesleft;
        int firsthalf;
        int secondhalf;
-       unsigned long flags;
 
        dbg("%s - port %d", __FUNCTION__, port->number);
 
@@ -1302,8 +1279,6 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
        // get a pointer to the Tx fifo
        fifo = &edge_port->txfifo;
 
-       spin_lock_irqsave(&edge_port->ep_lock, flags);
-
        // calculate number of bytes to put in fifo
        copySize = min ((unsigned int)count, (edge_port->txCredits - fifo->count));
 
@@ -1313,7 +1288,7 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
        /* catch writes of 0 bytes which the tty driver likes to give us, and when txCredits is empty */
        if (copySize == 0) {
                dbg("%s - copySize = Zero", __FUNCTION__);
-               goto finish_write;
+               return 0;
        }
 
        // queue the data       
@@ -1327,7 +1302,12 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
        dbg("%s - copy %d bytes of %d into fifo ", __FUNCTION__, firsthalf, bytesleft);
 
        /* now copy our data */
-       memcpy(&fifo->fifo[fifo->head], data, firsthalf);
+       if (from_user) {
+               if (copy_from_user(&fifo->fifo[fifo->head], data, firsthalf))
+                       return -EFAULT;
+       } else {
+               memcpy(&fifo->fifo[fifo->head], data, firsthalf);
+       }  
        usb_serial_debug_data(debug, &port->dev, __FUNCTION__, firsthalf, &fifo->fifo[fifo->head]);
 
        // update the index and size
@@ -1343,7 +1323,12 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
 
        if (secondhalf) {
                dbg("%s - copy rest of data %d", __FUNCTION__, secondhalf);
-               memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
+               if (from_user) {
+                       if (copy_from_user(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf))
+                               return -EFAULT;
+               } else {
+                       memcpy(&fifo->fifo[fifo->head], &data[firsthalf], secondhalf);
+               }
                usb_serial_debug_data(debug, &port->dev, __FUNCTION__, secondhalf, &fifo->fifo[fifo->head]);
                // update the index and size
                fifo->count += secondhalf;
@@ -1351,9 +1336,6 @@ static int edge_write (struct usb_serial_port *port, const unsigned char *data,
                // No need to check for wrap since we can not get to end of fifo in this part
        }
 
-finish_write:
-       spin_unlock_irqrestore(&edge_port->ep_lock, flags);
-
        send_more_port_data((struct edgeport_serial *)usb_get_serial_data(port->serial), edge_port);
 
        dbg("%s wrote %d byte(s) TxCredits %d, Fifo %d", __FUNCTION__, copySize, edge_port->txCredits, fifo->count);
@@ -1385,17 +1367,14 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
        int             bytesleft;
        int             firsthalf;
        int             secondhalf;
-       unsigned long   flags;
 
        dbg("%s(%d)", __FUNCTION__, edge_port->port->number);
 
-       spin_lock_irqsave(&edge_port->ep_lock, flags);
-
        if (edge_port->write_in_progress ||
            !edge_port->open             ||
            (fifo->count == 0)) {
                dbg("%s(%d) EXIT - fifo %d, PendingWrite = %d", __FUNCTION__, edge_port->port->number, fifo->count, edge_port->write_in_progress);
-               goto exit_send;
+               return;
        }
 
        // since the amount of data in the fifo will always fit into the
@@ -1407,7 +1386,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
        //      write.
        if (edge_port->txCredits < EDGE_FW_GET_TX_CREDITS_SEND_THRESHOLD(edge_port->maxTxCredits,EDGE_FW_BULK_MAX_PACKET_SIZE)) {
                dbg("%s(%d) Not enough credit - fifo %d TxCredit %d", __FUNCTION__, edge_port->port->number, fifo->count, edge_port->txCredits );
-               goto exit_send;
+               return;
        }
 
        // lock this write
@@ -1428,7 +1407,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
        if (buffer == NULL) {
                dev_err(&edge_port->port->dev, "%s - no more kernel memory...\n", __FUNCTION__);
                edge_port->write_in_progress = FALSE;
-               goto exit_send;
+               return;
        }
        buffer[0] = IOSP_BUILD_DATA_HDR1 (edge_port->port->number - edge_port->port->serial->minor, count);
        buffer[1] = IOSP_BUILD_DATA_HDR2 (edge_port->port->number - edge_port->port->serial->minor, count);
@@ -1466,7 +1445,7 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
        status = usb_submit_urb(urb, GFP_ATOMIC);
        if (status) {
                /* something went wrong */
-               dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write bulk) failed, status = %d, data lost\n", __FUNCTION__, status);
+               dbg("%s - usb_submit_urb(write bulk) failed", __FUNCTION__);
                edge_port->write_in_progress = FALSE;
 
                /* revert the credits as something bad happened. */
@@ -1474,9 +1453,6 @@ static void send_more_port_data(struct edgeport_serial *edge_serial, struct edge
                edge_port->icount.tx -= count;
        }
        dbg("%s wrote %d byte(s) TxCredit %d, Fifo %d", __FUNCTION__, count, edge_port->txCredits, fifo->count);
-
-exit_send:
-       spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 }
 
 
@@ -1490,9 +1466,8 @@ exit_send:
  *****************************************************************************/
 static int edge_write_room (struct usb_serial_port *port)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        int room;
-       unsigned long flags;
 
        dbg("%s", __FUNCTION__);
 
@@ -1509,9 +1484,7 @@ static int edge_write_room (struct usb_serial_port *port)
        }
 
        // total of both buffers is still txCredit
-       spin_lock_irqsave(&edge_port->ep_lock, flags);
        room = edge_port->txCredits - edge_port->txfifo.count;
-       spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 
        dbg("%s - returns %d", __FUNCTION__, room);
        return room;
@@ -1529,9 +1502,8 @@ static int edge_write_room (struct usb_serial_port *port)
  *****************************************************************************/
 static int edge_chars_in_buffer (struct usb_serial_port *port)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        int num_chars;
-       unsigned long flags;
 
        dbg("%s", __FUNCTION__);
 
@@ -1545,9 +1517,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
                return -EINVAL;
        }
 
-       spin_lock_irqsave(&edge_port->ep_lock, flags);
        num_chars = edge_port->maxTxCredits - edge_port->txCredits + edge_port->txfifo.count;
-       spin_unlock_irqrestore(&edge_port->ep_lock, flags);
        if (num_chars) {
                dbg("%s(port %d) - returns %d", __FUNCTION__, port->number, num_chars);
        }
@@ -1563,7 +1533,7 @@ static int edge_chars_in_buffer (struct usb_serial_port *port)
  *****************************************************************************/
 static void edge_throttle (struct usb_serial_port *port)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        struct tty_struct *tty;
        int status;
 
@@ -1586,7 +1556,7 @@ static void edge_throttle (struct usb_serial_port *port)
        /* if we are implementing XON/XOFF, send the stop character */
        if (I_IXOFF(tty)) {
                unsigned char stop_char = STOP_CHAR(tty);
-               status = edge_write (port, &stop_char, 1);
+               status = edge_write (port, 0, &stop_char, 1);
                if (status <= 0) {
                        return;
                }
@@ -1612,7 +1582,7 @@ static void edge_throttle (struct usb_serial_port *port)
  *****************************************************************************/
 static void edge_unthrottle (struct usb_serial_port *port)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        struct tty_struct *tty;
        int status;
 
@@ -1635,7 +1605,7 @@ static void edge_unthrottle (struct usb_serial_port *port)
        /* if we are implementing XON/XOFF, send the start character */
        if (I_IXOFF(tty)) {
                unsigned char start_char = START_CHAR(tty);
-               status = edge_write (port, &start_char, 1);
+               status = edge_write (port, 0, &start_char, 1);
                if (status <= 0) {
                        return;
                }
@@ -1660,7 +1630,7 @@ static void edge_unthrottle (struct usb_serial_port *port)
  *****************************************************************************/
 static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        struct tty_struct *tty = port->tty;
        unsigned int cflag;
 
@@ -1672,18 +1642,20 @@ static void edge_set_termios (struct usb_serial_port *port, struct termios *old_
        cflag = tty->termios->c_cflag;
        /* check that they really want us to change something */
        if (old_termios) {
-               if (cflag == old_termios->c_cflag &&
-                   tty->termios->c_iflag == old_termios->c_iflag) {
+               if ((cflag == old_termios->c_cflag) &&
+                   (RELEVANT_IFLAG(tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
                        dbg("%s - nothing to change", __FUNCTION__);
                        return;
                }
        }
 
        dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 
-           tty->termios->c_cflag, tty->termios->c_iflag);
+           tty->termios->c_cflag,
+           RELEVANT_IFLAG(tty->termios->c_iflag));
        if (old_termios) {
                dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
-                   old_termios->c_cflag, old_termios->c_iflag);
+                   old_termios->c_cflag,
+                   RELEVANT_IFLAG(old_termios->c_iflag));
        }
 
        dbg("%s - port %d", __FUNCTION__, port->number);
@@ -1716,15 +1688,12 @@ static void edge_set_termios (struct usb_serial_port *port, struct termios *old_
 static int get_lsr_info(struct edgeport_port *edge_port, unsigned int __user *value)
 {
        unsigned int result = 0;
-       unsigned long flags;
 
-       spin_lock_irqsave(&edge_port->ep_lock, flags);
        if (edge_port->maxTxCredits == edge_port->txCredits &&
            edge_port->txfifo.count == 0) {
                dbg("%s -- Empty", __FUNCTION__);
                result = TIOCSER_TEMT;
        }
-       spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 
        if (copy_to_user(value, &result, sizeof(int)))
                return -EFAULT;
@@ -1750,7 +1719,7 @@ static int get_number_bytes_avail(struct edgeport_port *edge_port, unsigned int
 
 static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        unsigned int mcr;
 
        dbg("%s - port %d", __FUNCTION__, port->number);
@@ -1779,7 +1748,7 @@ static int edge_tiocmset (struct usb_serial_port *port, struct file *file, unsig
 
 static int edge_tiocmget(struct usb_serial_port *port, struct file *file)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        unsigned int result = 0;
        unsigned int msr;
        unsigned int mcr;
@@ -1836,7 +1805,7 @@ static int get_serial_info(struct edgeport_port *edge_port, struct serial_struct
  *****************************************************************************/
 static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        struct async_icount cnow;
        struct async_icount cprev;
        struct serial_icounter_struct icount;
@@ -1918,7 +1887,7 @@ static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned
  *****************************************************************************/
 static void edge_break (struct usb_serial_port *port, int break_state)
 {
-       struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
        int status;
 
        /* flush and chase */
@@ -1952,13 +1921,14 @@ static void edge_break (struct usb_serial_port *port, int break_state)
  * process_rcvd_data
  *     this function handles the data received on the bulk in pipe.
  *****************************************************************************/
-static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char * buffer, __u16 bufferLength)
+static int process_rcvd_data (struct edgeport_serial *edge_serial, unsigned char * buffer, __u16 bufferLength)
 {
        struct usb_serial_port *port;
        struct edgeport_port *edge_port;
        struct tty_struct *tty;
        __u16 lastBufferLength;
        __u16 rxLen;
+       int i;
 
        dbg("%s", __FUNCTION__);
 
@@ -2013,6 +1983,7 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
 
                                        // We have all the header bytes, process the status now
                                        process_rcvd_status (edge_serial, edge_serial->rxHeader2, 0);
+
                                        edge_serial->rxState = EXPECT_HDR1;
                                        break;
                                } else {
@@ -2053,7 +2024,15 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
                                                tty = edge_port->port->tty;
                                                if (tty) {
                                                        dbg("%s - Sending %d bytes to TTY for port %d", __FUNCTION__, rxLen, edge_serial->rxPort);
-                                                       edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen);
+                                                       for (i = 0; i < rxLen ; ++i) {
+                                                               /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
+                                                               if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
+                                                                       tty_flip_buffer_push(tty);
+                                                               }
+                                                               /* this doesn't actually push the data through unless tty->low_latency is set */
+                                                               tty_insert_flip_char(tty, buffer[i], 0);
+                                                       }
+                                                       tty_flip_buffer_push(tty);
                                                }
                                                edge_port->icount.rx += rxLen;
                                        }
@@ -2074,6 +2053,8 @@ static void process_rcvd_data (struct edgeport_serial *edge_serial, unsigned cha
 
                }
        }
+
+       return 0;
 }
 
 
@@ -2089,7 +2070,7 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
 
        /* switch the port pointer to the one being currently talked about */
        port = edge_serial->serial->port[edge_serial->rxPort];
-       edge_port = usb_get_serial_port_data(port);
+        edge_port = usb_get_serial_port_data(port);
        if (edge_port == NULL) {
                dev_err(&edge_serial->serial->dev->dev, "%s - edge_port == NULL for port %d\n", __FUNCTION__, edge_serial->rxPort);
                return;
@@ -2178,37 +2159,6 @@ static void process_rcvd_status (struct edgeport_serial *edge_serial, __u8 byte2
 }
 
 
-/*****************************************************************************
- * edge_tty_recv
- *     this function passes data on to the tty flip buffer
- *****************************************************************************/
-static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length)
-{
-       int cnt;
-
-       do {
-               if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-                       tty_flip_buffer_push(tty);
-                       if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
-                               dev_err(dev, "%s - dropping data, %d bytes lost\n",
-                                       __FUNCTION__, length);
-                               return;
-                       }
-               }
-               cnt = min(length, TTY_FLIPBUF_SIZE - tty->flip.count);
-               memcpy(tty->flip.char_buf_ptr, data, cnt);
-               memset(tty->flip.flag_buf_ptr, 0, cnt);
-               tty->flip.char_buf_ptr += cnt;
-               tty->flip.flag_buf_ptr += cnt;
-               tty->flip.count += cnt;
-               data += cnt;
-               length -= cnt;
-       } while (length > 0);
-
-       tty_flip_buffer_push(tty);
-}
-
-
 /*****************************************************************************
  * handle_new_msr
  *     this function handles any change to the msr register for a port.
@@ -2268,8 +2218,10 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData, __u8 l
        }
 
        /* Place LSR data byte into Rx buffer */
-       if (lsrData && edge_port->port->tty)
-               edge_tty_recv(&edge_port->port->dev, edge_port->port->tty, &data, 1);
+       if (lsrData && edge_port->port->tty) {
+               tty_insert_flip_char(edge_port->port->tty, data, 0);
+               tty_flip_buffer_push(edge_port->port->tty);
+       }
 
        /* update input line counters */
        icount = &edge_port->icount;
@@ -2490,10 +2442,9 @@ static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer
 
        if (status) {
                /* something went wrong */
-               dev_err(&edge_port->port->dev, "%s - usb_submit_urb(write command) failed, status = %d\n", __FUNCTION__, status);
-               usb_kill_urb(urb);
-               usb_free_urb(urb);
-               CmdUrbs--;
+               dbg("%s - usb_submit_urb(write bulk) failed", __FUNCTION__);
+               usb_unlink_urb (urb);
+               usb_free_urb   (urb);
                return status;
        }
 
@@ -2573,6 +2524,8 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
 {
        int i;
        __u16 custom;
+       __u16 round1;
+       __u16 round;
 
 
        dbg("%s - %d", __FUNCTION__, baudrate);
@@ -2587,10 +2540,16 @@ static int calc_baud_rate_divisor (int baudrate, int *divisor)
        // We have tried all of the standard baud rates
        // lets try to calculate the divisor for this baud rate
        // Make sure the baud rate is reasonable
-       if (baudrate > 50 && baudrate < 230400) {
+       if (baudrate < 230400) {
                // get divisor
-               custom = (__u16)((230400L + baudrate/2) / baudrate);
+               custom = (__u16)(230400L  / baudrate);
 
+               // Check for round off
+               round1 = (__u16)(2304000L / baudrate);
+               round = (__u16)(round1 - (custom * 10));
+               if (round > 4) {
+                       custom++;
+               }
                *divisor = custom;
 
                dbg("%s - Baud %d = %d\n", __FUNCTION__, baudrate, custom);
@@ -2642,9 +2601,6 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
  *     This routine is called to set the UART on the device to match the specified
  *     new settings.
  *****************************************************************************/
-#ifndef CMSPAR
-#define CMSPAR 0
-#endif
 static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios)
 {
        struct tty_struct *tty;
@@ -2685,15 +2641,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct termio
 
        lParity = LCR_PAR_NONE;
        if (cflag & PARENB) {
-               if (cflag & CMSPAR) {
-                       if (cflag & PARODD) {
-                               lParity = LCR_PAR_MARK;
-                               dbg("%s - parity = mark", __FUNCTION__);
-                       } else {
-                               lParity = LCR_PAR_SPACE;
-                               dbg("%s - parity = space", __FUNCTION__);
-                       }
-               } else if (cflag & PARODD) {
+               if (cflag & PARODD) {
                        lParity = LCR_PAR_ODD;
                        dbg("%s - parity = odd", __FUNCTION__);
                } else {
@@ -2923,7 +2871,7 @@ static void load_application_firmware (struct edgeport_serial *edge_serial)
                record = (struct edge_firmware_image_record *)firmware;
                response = sram_write (edge_serial->serial, le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), le16_to_cpu(record->Len), &record->Data[0]);
                if (response < 0) {
-                       dev_err(&edge_serial->serial->dev->dev, "sram_write failed (%x, %x, %d)\n", le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), le16_to_cpu(record->Len));
+                       dev_err(&edge_serial->serial->dev->dev, "sram_write failed (%x, %x, %d)\n", le16_to_cpu(record->ExtAddr), le16_to_cpu(record->Addr), record->Len);
                        break;
                }
                firmware += sizeof (struct edge_firmware_image_record) + le16_to_cpu(record->Len);
@@ -2942,6 +2890,8 @@ static void load_application_firmware (struct edgeport_serial *edge_serial)
 }
 
 
+
+
 /****************************************************************************
  * edge_startup
  ****************************************************************************/
@@ -2957,11 +2907,10 @@ static int edge_startup (struct usb_serial *serial)
        /* create our private serial structure */
        edge_serial = kmalloc (sizeof(struct edgeport_serial), GFP_KERNEL);
        if (edge_serial == NULL) {
-               dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
+               dev_err(&serial->dev->dev, "%s - Out of memory", __FUNCTION__);
                return -ENOMEM;
        }
        memset (edge_serial, 0, sizeof(struct edgeport_serial));
-       spin_lock_init(&edge_serial->es_lock);
        edge_serial->serial = serial;
        usb_set_serial_data(serial, edge_serial);
 
@@ -3014,13 +2963,12 @@ static int edge_startup (struct usb_serial *serial)
        for (i = 0; i < serial->num_ports; ++i) {
                edge_port = kmalloc (sizeof(struct edgeport_port), GFP_KERNEL);
                if (edge_port == NULL) {
-                       dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
+                       dev_err(&serial->dev->dev, "%s - Out of memory", __FUNCTION__);
                        usb_set_serial_data(serial, NULL);
                        kfree(edge_serial);
                        return -ENOMEM;
                }
                memset (edge_port, 0, sizeof(struct edgeport_port));
-               spin_lock_init(&edge_port->ep_lock);
                edge_port->port = serial->port[i];
                usb_set_serial_port_data(serial->port[i], edge_port);
        }
@@ -3029,6 +2977,7 @@ static int edge_startup (struct usb_serial *serial)
 }
 
 
+
 /****************************************************************************
  * edge_shutdown
  *     This function is called whenever the device is removed from the usb bus.
@@ -3056,7 +3005,6 @@ static void edge_shutdown (struct usb_serial *serial)
 static int __init edgeport_init(void)
 {
        int retval;
-
        retval = usb_serial_register(&edgeport_2port_device);
        if (retval)
                goto failed_2port_device_register;
@@ -3071,7 +3019,6 @@ static int __init edgeport_init(void)
                goto failed_usb_register;
        info(DRIVER_DESC " " DRIVER_VERSION);
        return 0;
-
 failed_usb_register:
        usb_serial_deregister(&edgeport_8port_device);
 failed_8port_device_register:
@@ -3083,6 +3030,7 @@ failed_2port_device_register:
 }
 
 
+
 /****************************************************************************
  * edgeport_exit
  *     Called when the driver is about to be unloaded.
@@ -3105,6 +3053,3 @@ MODULE_LICENSE("GPL");
 
 module_param(debug, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug enabled or not");
-
-module_param(low_latency, bool, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(debug, "Low latency enabled or not");