Re: [PATCH 106/115] USB: PL2303: correctly handle baudrates above 115200

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

On 27-07-2011 8:06, Greg Kroah-Hartman wrote:

From: Michał Sroczyński<msroczyn@xxxxxxxxx>

PL2303: correctly handle baudrates above 115200

   Haven't seen this patch before, so have to comment now.

Signed-off-by: Michal Sroczynski<msroczyn@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman<gregkh@xxxxxxx>
---
  drivers/usb/serial/pl2303.c |   26 ++++++++++++++++++++++----
  1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 30461fc..ee28115 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -342,10 +342,28 @@ 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;
+			}
+			if (tmp > 256) {

This will never be true due to the *while* loop above. Also, {} are not needed.

+				tmp %= 256;
+			}
+			buf[0] = tmp;
+		}
  	}

  	/* For reference buf[4]=0 is 1 stop bits */

WBR, Sergei
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux