Merge branches 'release', 'asus', 'sony-laptop' and 'thinkpad' into release
[pandora-kernel.git] / drivers / usb / serial / mos7720.c
index b563e2a..40f3a01 100644 (file)
@@ -9,9 +9,9 @@
  * the Free Software Foundation, version 2 of the License.
  *
  * Developed by:
- *     VijayaKumar.G.N. <vijaykumar@aspirecom.net>
- *     AjayKumar <ajay@aspirecom.net>
- *     Gurudeva.N. <gurudev@aspirecom.net>
+ *     Vijaya Kumar <vijaykumar.gn@gmail.com>
+ *     Ajay Kumar <naanuajay@yahoo.com>
+ *     Gurudeva <ngurudeva@yahoo.com>
  *
  * Cleaned up from the original by:
  *     Greg Kroah-Hartman <gregkh@suse.de>
@@ -103,18 +103,14 @@ static void mos7720_interrupt_callback(struct urb *urb)
 {
        int result;
        int length;
+       int status = urb->status;
        __u8 *data;
        __u8 sp1;
        __u8 sp2;
 
        dbg("%s"," : Entering\n");
 
-       if (!urb) {
-               dbg("%s","Invalid Pointer !!!!:\n");
-               return;
-       }
-
-       switch (urb->status) {
+       switch (status) {
        case 0:
                /* success */
                break;
@@ -123,11 +119,11 @@ static void mos7720_interrupt_callback(struct urb *urb)
        case -ESHUTDOWN:
                /* this urb is terminated, clean up */
                dbg("%s - urb shutting down with status: %d", __FUNCTION__,
-                   urb->status);
+                   status);
                return;
        default:
                dbg("%s - nonzero urb status received: %d", __FUNCTION__,
-                   urb->status);
+                   status);
                goto exit;
        }
 
@@ -198,14 +194,15 @@ exit:
  */
 static void mos7720_bulk_in_callback(struct urb *urb)
 {
-       int status;
+       int retval;
        unsigned char *data ;
        struct usb_serial_port *port;
        struct moschip_port *mos7720_port;
        struct tty_struct *tty;
+       int status = urb->status;
 
-       if (urb->status) {
-               dbg("nonzero read bulk status received: %d",urb->status);
+       if (status) {
+               dbg("nonzero read bulk status received: %d", status);
                return;
        }
 
@@ -236,10 +233,10 @@ static void mos7720_bulk_in_callback(struct urb *urb)
        if (port->read_urb->status != -EINPROGRESS) {
                port->read_urb->dev = port->serial->dev;
 
-               status = usb_submit_urb(port->read_urb, GFP_ATOMIC);
-               if (status)
-                       dbg("usb_submit_urb(read bulk) failed, status = %d",
-                           status);
+               retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
+               if (retval)
+                       dbg("usb_submit_urb(read bulk) failed, retval = %d",
+                           retval);
        }
 }
 
@@ -252,9 +249,10 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
 {
        struct moschip_port *mos7720_port;
        struct tty_struct *tty;
+       int status = urb->status;
 
-       if (urb->status) {
-               dbg("nonzero write bulk status received:%d", urb->status);
+       if (status) {
+               dbg("nonzero write bulk status received:%d", status);
                return;
        }
 
@@ -480,7 +478,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
                response = usb_submit_urb(port0->interrupt_in_urb, GFP_KERNEL);
                if (response)
                        dev_err(&port->dev,
-                               "%s - Error %d submitting control urb",
+                               "%s - Error %d submitting control urb\n",
                                __FUNCTION__, response);
        }
 
@@ -494,7 +492,7 @@ static int mos7720_open(struct usb_serial_port *port, struct file * filp)
        response = usb_submit_urb(port->read_urb, GFP_KERNEL);
        if (response)
                dev_err(&port->dev,
-                       "%s - Error %d submitting read urb", __FUNCTION__, response);
+                       "%s - Error %d submitting read urb\n", __FUNCTION__, response);
 
        /* initialize our icount structure */
        memset(&(mos7720_port->icount), 0x00, sizeof(mos7720_port->icount));
@@ -566,22 +564,25 @@ static void mos7720_close(struct usb_serial_port *port, struct file *filp)
        }
 
        /* While closing port, shutdown all bulk read, write  *
-        * and interrupt read if they exists                  */
-       if (serial->dev) {
-               dbg("Shutdown bulk write");
-               usb_kill_urb(port->write_urb);
-               dbg("Shutdown bulk read");
-               usb_kill_urb(port->read_urb);
+        * and interrupt read if they exists, otherwise nop   */
+       dbg("Shutdown bulk write");
+       usb_kill_urb(port->write_urb);
+       dbg("Shutdown bulk read");
+       usb_kill_urb(port->read_urb);
+
+       mutex_lock(&serial->disc_mutex);
+       /* these commands must not be issued if the device has
+        * been disconnected */
+       if (!serial->disconnected) {
+               data = 0x00;
+               send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
+                            0x04, &data);
+
+               data = 0x00;
+               send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
+                            0x01, &data);
        }
-
-       data = 0x00;
-       send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
-                    0x04, &data);
-
-       data = 0x00;
-       send_mos_cmd(serial, MOS_WRITE, port->number - port->serial->minor,
-                    0x01, &data);
-
+       mutex_unlock(&serial->disc_mutex);
        mos7720_port->open = 0;
 
        dbg("Leaving %s", __FUNCTION__);
@@ -1042,11 +1043,6 @@ static void change_port_settings(struct moschip_port *mos7720_port,
 
        tty = mos7720_port->port->tty;
 
-       if ((!tty) || (!tty->termios)) {
-               dbg("%s - no tty structures", __FUNCTION__);
-               return;
-       }
-
        dbg("%s: Entering ..........", __FUNCTION__);
 
        lData = UART_LCR_WLEN8;
@@ -1177,7 +1173,10 @@ static void change_port_settings(struct moschip_port *mos7720_port,
 
        dbg("%s - baud rate = %d", __FUNCTION__, baud);
        status = send_cmd_write_baud_rate(mos7720_port, baud);
-
+       /* FIXME: needs to write actual resulting baud back not just
+          blindly do so */
+       if (cflag & CBAUD)
+               tty_encode_baud_rate(tty, baud, baud);
        /* Enable Interrupts */
        data = 0x0c;
        send_mos_cmd(serial, MOS_WRITE, port_number, UART_IER, &data);
@@ -1216,10 +1215,6 @@ static void mos7720_set_termios(struct usb_serial_port *port,
 
        tty = port->tty;
 
-       if (!port->tty || !port->tty->termios) {
-               dbg("%s - no tty or termios", __FUNCTION__);
-               return;
-       }
 
        if (!mos7720_port->open) {
                dbg("%s - port not opened", __FUNCTION__);
@@ -1230,29 +1225,13 @@ static void mos7720_set_termios(struct usb_serial_port *port,
 
        cflag = tty->termios->c_cflag;
 
-       if (!cflag) {
-               printk("%s %s\n",__FUNCTION__,"cflag is NULL");
-               return;
-       }
-
-       /* check that they really want us to change something */
-       if (old_termios) {
-               if ((cflag == old_termios->c_cflag) &&
-                   (RELEVANT_IFLAG(tty->termios->c_iflag) ==
-                    RELEVANT_IFLAG(old_termios->c_iflag))) {
-                       dbg("Nothing to change");
-                       return;
-               }
-       }
-
-       dbg("%s - clfag %08x iflag %08x", __FUNCTION__,
+       dbg("%s - cflag %08x iflag %08x", __FUNCTION__,
            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,
-                   RELEVANT_IFLAG(old_termios->c_iflag));
+       dbg("%s - old cflag %08x old iflag %08x", __FUNCTION__,
+           old_termios->c_cflag,
+           RELEVANT_IFLAG(old_termios->c_iflag));
 
        dbg("%s - port %d", __FUNCTION__, port->number);