USB: pl2303: fix DTR/RTS being raised on baud rate change
[linux-flexiantxendom0.git] / drivers / usb / serial / pl2303.c
index 30461fc..5532ea5 100644 (file)
@@ -91,6 +91,7 @@ static const struct usb_device_id id_table[] = {
        { USB_DEVICE(SONY_VENDOR_ID, SONY_QN3USB_PRODUCT_ID) },
        { USB_DEVICE(SANWA_VENDOR_ID, SANWA_PRODUCT_ID) },
        { USB_DEVICE(ADLINK_VENDOR_ID, ADLINK_ND6530_PRODUCT_ID) },
+       { USB_DEVICE(SMART_VENDOR_ID, SMART_PRODUCT_ID) },
        { }                                     /* Terminating entry */
 };
 
@@ -342,10 +343,25 @@ static void pl2303_set_termios(struct tty_struct *tty,
                                baud = 6000000;
                }
                dbg("%s - baud set = %d", __func__, baud);
-               buf[0] = baud & 0xff;
-               buf[1] = (baud >> 8) & 0xff;
-               buf[2] = (baud >> 16) & 0xff;
-               buf[3] = (baud >> 24) & 0xff;
+               if (baud <= 115200) {
+                       buf[0] = baud & 0xff;
+                       buf[1] = (baud >> 8) & 0xff;
+                       buf[2] = (baud >> 16) & 0xff;
+                       buf[3] = (baud >> 24) & 0xff;
+               } else {
+                       /* apparently the formula for higher speeds is:
+                        * baudrate = 12M * 32 / (2^buf[1]) / buf[0]
+                        */
+                       unsigned tmp = 12*1000*1000*32 / baud;
+                       buf[3] = 0x80;
+                       buf[2] = 0;
+                       buf[1] = (tmp >= 256);
+                       while (tmp >= 256) {
+                               tmp >>= 2;
+                               buf[1] <<= 1;
+                       }
+                       buf[0] = tmp;
+               }
        }
 
        /* For reference buf[4]=0 is 1 stop bits */
@@ -405,7 +421,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
        control = priv->line_control;
        if ((cflag & CBAUD) == B0)
                priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
-       else
+       else if ((old_termios->c_cflag & CBAUD) == B0)
                priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
        if (control != priv->line_control) {
                control = priv->line_control;