]> err.no Git - linux-2.6/blobdiff - drivers/usb/serial/io_ti.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux-2.6] / drivers / usb / serial / io_ti.c
index fbc2e024c335e79bdd6b9cbc2ef87ce4766b48ad..e5ea5ef6335d1acc42e3049fe507eb92b35a3222 100644 (file)
 #include <linux/tty_flip.h>
 #include <linux/module.h>
 #include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/serial.h>
 #include <linux/ioctl.h>
 #include <asm/uaccess.h>
-#include <asm/semaphore.h>
 #include <linux/usb.h>
 #include <linux/usb/serial.h>
 
@@ -133,7 +133,7 @@ struct edgeport_serial {
        struct product_info product_info;
        u8 TI_I2C_Type;                 // Type of I2C in UMP
        u8 TiReadI2C;                   // Set to TRUE if we have read the I2c in Boot Mode
-       struct semaphore es_sem;
+       struct mutex es_lock;
        int num_ports_open;
        struct usb_serial *serial;
 };
@@ -1719,13 +1719,14 @@ static void edge_interrupt_callback (struct urb *urb)
        int length = urb->actual_length;
        int port_number;
        int function;
-       int status;
+       int retval;
        __u8 lsr;
        __u8 msr;
+       int status = urb->status;
 
        dbg("%s", __FUNCTION__);
 
-       switch (urb->status) {
+       switch (status) {
        case 0:
                /* success */
                break;
@@ -1733,10 +1734,12 @@ static void edge_interrupt_callback (struct urb *urb)
        case -ENOENT:
        case -ESHUTDOWN:
                /* this urb is terminated, clean up */
-               dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
+               dbg("%s - urb shutting down with status: %d",
+                   __FUNCTION__, status);
                return;
        default:
-               dev_err(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __FUNCTION__, urb->status);
+               dev_err(&urb->dev->dev, "%s - nonzero urb status received: "
+                       "%d\n", __FUNCTION__, status);
                goto exit;
        }
 
@@ -1794,10 +1797,10 @@ static void edge_interrupt_callback (struct urb *urb)
        }
 
 exit:
-       status = usb_submit_urb (urb, GFP_ATOMIC);
-       if (status)
+       retval = usb_submit_urb (urb, GFP_ATOMIC);
+       if (retval)
                dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
-                        __FUNCTION__, status);
+                        __FUNCTION__, retval);
 }
 
 static void edge_bulk_in_callback (struct urb *urb)
@@ -1805,12 +1808,13 @@ static void edge_bulk_in_callback (struct urb *urb)
        struct edgeport_port *edge_port = (struct edgeport_port *)urb->context;
        unsigned char *data = urb->transfer_buffer;
        struct tty_struct *tty;
-       int status = 0;
+       int retval = 0;
        int port_number;
+       int status = urb->status;
 
        dbg("%s", __FUNCTION__);
 
-       switch (urb->status) {
+       switch (status) {
        case 0:
                /* success */
                break;
@@ -1818,17 +1822,18 @@ static void edge_bulk_in_callback (struct urb *urb)
        case -ENOENT:
        case -ESHUTDOWN:
                /* this urb is terminated, clean up */
-               dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
+               dbg("%s - urb shutting down with status: %d",
+                   __FUNCTION__, status);
                return;
        default:
                dev_err (&urb->dev->dev,"%s - nonzero read bulk status received: %d\n",
-                    __FUNCTION__, urb->status );
+                    __FUNCTION__, status);
        }
 
-       if (urb->status == -EPIPE)
+       if (status == -EPIPE)
                goto exit;
 
-       if (urb->status) {
+       if (status) {
                dev_err(&urb->dev->dev,"%s - stopping read!\n", __FUNCTION__);
                return;
        }
@@ -1862,14 +1867,14 @@ exit:
        spin_lock(&edge_port->ep_lock);
        if (edge_port->ep_read_urb_state == EDGE_READ_URB_RUNNING) {
                urb->dev = edge_port->port->serial->dev;
-               status = usb_submit_urb(urb, GFP_ATOMIC);
+               retval = usb_submit_urb(urb, GFP_ATOMIC);
        } else if (edge_port->ep_read_urb_state == EDGE_READ_URB_STOPPING) {
                edge_port->ep_read_urb_state = EDGE_READ_URB_STOPPED;
        }
        spin_unlock(&edge_port->ep_lock);
-       if (status)
+       if (retval)
                dev_err (&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
-                        __FUNCTION__, status);
+                        __FUNCTION__, retval);
 }
 
 static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned char *data, int length)
@@ -1896,12 +1901,13 @@ static void edge_bulk_out_callback (struct urb *urb)
 {
        struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
        struct edgeport_port *edge_port = usb_get_serial_port_data(port);
+       int status = urb->status;
 
        dbg ("%s - port %d", __FUNCTION__, port->number);
 
        edge_port->ep_write_urb_in_use = 0;
 
-       switch (urb->status) {
+       switch (status) {
        case 0:
                /* success */
                break;
@@ -1909,11 +1915,12 @@ static void edge_bulk_out_callback (struct urb *urb)
        case -ENOENT:
        case -ESHUTDOWN:
                /* this urb is terminated, clean up */
-               dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
+               dbg("%s - urb shutting down with status: %d",
+                   __FUNCTION__, status);
                return;
        default:
-               dev_err (&urb->dev->dev,"%s - nonzero write bulk status received: %d\n",
-                    __FUNCTION__, urb->status);
+               dev_err(&urb->dev->dev, "%s - nonzero write bulk status "
+                       "received: %d\n", __FUNCTION__, status);
        }
 
        /* send any buffered data */
@@ -1971,7 +1978,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
        }
        
        /* set up the port settings */
-       edge_set_termios (port, NULL);
+       edge_set_termios (port, port->tty->termios);
 
        /* open up the port */
 
@@ -2037,7 +2044,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
        dbg ("ShadowMCR 0x%X", edge_port->shadow_mcr);
 
        edge_serial = edge_port->edge_serial;
-       if (down_interruptible(&edge_serial->es_sem))
+       if (mutex_lock_interruptible(&edge_serial->es_lock))
                return -ERESTARTSYS;
        if (edge_serial->num_ports_open == 0) {
                /* we are the first port to be opened, let's post the interrupt urb */
@@ -2045,7 +2052,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
                if (!urb) {
                        dev_err (&port->dev, "%s - no interrupt urb present, exiting\n", __FUNCTION__);
                        status = -EINVAL;
-                       goto up_es_sem;
+                       goto release_es_lock;
                }
                urb->complete = edge_interrupt_callback;
                urb->context = edge_serial;
@@ -2053,7 +2060,7 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
                status = usb_submit_urb (urb, GFP_KERNEL);
                if (status) {
                        dev_err (&port->dev, "%s - usb_submit_urb failed with value %d\n", __FUNCTION__, status);
-                       goto up_es_sem;
+                       goto release_es_lock;
                }
        }
 
@@ -2085,13 +2092,13 @@ static int edge_open (struct usb_serial_port *port, struct file * filp)
 
        dbg("%s - exited", __FUNCTION__);
 
-       goto up_es_sem;
+       goto release_es_lock;
 
 unlink_int_urb:
        if (edge_port->edge_serial->num_ports_open == 0)
                usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
-up_es_sem:
-       up(&edge_serial->es_sem);
+release_es_lock:
+       mutex_unlock(&edge_serial->es_lock);
        return status;
 }
 
@@ -2130,14 +2137,14 @@ static void edge_close (struct usb_serial_port *port, struct file *filp)
                                     0,
                                     NULL,
                                     0);
-       down(&edge_serial->es_sem);
+       mutex_lock(&edge_serial->es_lock);
        --edge_port->edge_serial->num_ports_open;
        if (edge_port->edge_serial->num_ports_open <= 0) {
                /* last port is now closed, let's shut down our interrupt urb */
                usb_kill_urb(port->serial->port[0]->interrupt_in_urb);
                edge_port->edge_serial->num_ports_open = 0;
        }
-       up(&edge_serial->es_sem);
+       mutex_unlock(&edge_serial->es_lock);
        edge_port->close_pending = 0;
 
        dbg("%s - exited", __FUNCTION__);
@@ -2386,11 +2393,6 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
        dbg("%s - port %d", __FUNCTION__, edge_port->port->number);
 
        tty = edge_port->port->tty;
-       if ((!tty) ||
-           (!tty->termios)) {
-               dbg("%s - no tty structures", __FUNCTION__);
-               return;
-       }
 
        config = kmalloc (sizeof (*config), GFP_KERNEL);
        if (!config) {
@@ -2485,15 +2487,21 @@ static void change_port_settings (struct edgeport_port *edge_port, struct ktermi
                }
        }
 
+       tty->termios->c_cflag &= ~CMSPAR;
+
        /* Round the baud rate */
        baud = tty_get_baud_rate(tty);
        if (!baud) {
                /* pick a default, any default... */
                baud = 9600;
-       }
+       } else
+               tty_encode_baud_rate(tty, baud, baud);
+
        edge_port->baud_rate = baud;
        config->wBaudRate = (__u16)((461550L + baud/2) / baud);
 
+       /* FIXME: Recompute actual baud from divisor here */
+
        dbg ("%s - baud rate = %d, wBaudRate = %d", __FUNCTION__, baud, config->wBaudRate);
 
        dbg ("wBaudRate:   %d", (int)(461550L / config->wBaudRate));
@@ -2531,27 +2539,12 @@ static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old
        struct tty_struct *tty = port->tty;
        unsigned int cflag;
 
-       if (!port->tty || !port->tty->termios) {
-               dbg ("%s - no tty or termios", __FUNCTION__);
-               return;
-       }
-
        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) {
-                       dbg ("%s - nothing to change", __FUNCTION__);
-                       return;
-               }
-       }
 
        dbg("%s - clfag %08x iflag %08x", __FUNCTION__, 
            tty->termios->c_cflag, tty->termios->c_iflag);
-       if (old_termios) {
-               dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
-                   old_termios->c_cflag, old_termios->c_iflag);
-       }
+       dbg("%s - old clfag %08x old iflag %08x", __FUNCTION__,
+           old_termios->c_cflag, old_termios->c_iflag);
 
        dbg("%s - port %d", __FUNCTION__, port->number);
 
@@ -2744,7 +2737,7 @@ static int edge_startup (struct usb_serial *serial)
                dev_err(&serial->dev->dev, "%s - Out of memory\n", __FUNCTION__);
                return -ENOMEM;
        }
-       sema_init(&edge_serial->es_sem, 1);
+       mutex_init(&edge_serial->es_lock);
        edge_serial->serial = serial;
        usb_set_serial_data(serial, edge_serial);
 
@@ -2795,16 +2788,14 @@ static void edge_shutdown (struct usb_serial *serial)
 
        dbg ("%s", __FUNCTION__);
 
-       for (i=0; i < serial->num_ports; ++i) {
+       for (i = 0; i < serial->num_ports; ++i) {
                edge_port = usb_get_serial_port_data(serial->port[i]);
                edge_remove_sysfs_attrs(edge_port->port);
-               if (edge_port) {
-                       edge_buf_free(edge_port->ep_out_buf);
-                       kfree(edge_port);
-               }
+               edge_buf_free(edge_port->ep_out_buf);
+               kfree(edge_port);
                usb_set_serial_port_data(serial->port[i], NULL);
        }
-       kfree (usb_get_serial_data(serial));
+       kfree(usb_get_serial_data(serial));
        usb_set_serial_data(serial, NULL);
 }