diff options
author | Johan Hovold <jhovold@gmail.com> | 2013-12-29 13:23:13 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-03 15:31:48 -0500 |
commit | c82c6d45a2fc882fedfde517ba86690b2d5ed555 (patch) | |
tree | 4e5192dca62e8c971300bcc380db6d83b67d2815 /drivers/usb/serial | |
parent | 871996ede12306cd1d75ed8135bed6f1fcbcd0e6 (diff) |
USB: pl2303: refactor baud-rate divisor handling
Refactor baud-rate divisor handling.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r-- | drivers/usb/serial/pl2303.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 394903b4ecb7..44f4b546adeb 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -339,6 +339,28 @@ static speed_t pl2303_get_supported_baud_rate(speed_t baud) | |||
339 | return baud; | 339 | return baud; |
340 | } | 340 | } |
341 | 341 | ||
342 | static speed_t pl2303_encode_baud_rate_divisor(unsigned char buf[4], | ||
343 | speed_t baud) | ||
344 | { | ||
345 | unsigned int tmp; | ||
346 | |||
347 | /* | ||
348 | * Apparently the formula is: | ||
349 | * baudrate = 12M * 32 / (2^buf[1]) / buf[0] | ||
350 | */ | ||
351 | tmp = 12000000 * 32 / baud; | ||
352 | buf[3] = 0x80; | ||
353 | buf[2] = 0; | ||
354 | buf[1] = (tmp >= 256); | ||
355 | while (tmp >= 256) { | ||
356 | tmp >>= 2; | ||
357 | buf[1] <<= 1; | ||
358 | } | ||
359 | buf[0] = tmp; | ||
360 | |||
361 | return baud; | ||
362 | } | ||
363 | |||
342 | static void pl2303_encode_baud_rate(struct tty_struct *tty, | 364 | static void pl2303_encode_baud_rate(struct tty_struct *tty, |
343 | struct usb_serial_port *port, | 365 | struct usb_serial_port *port, |
344 | u8 buf[4]) | 366 | u8 buf[4]) |
@@ -362,23 +384,10 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty, | |||
362 | */ | 384 | */ |
363 | baud = pl2303_get_supported_baud_rate(baud); | 385 | baud = pl2303_get_supported_baud_rate(baud); |
364 | 386 | ||
365 | if (baud <= 115200) { | 387 | if (baud <= 115200) |
366 | put_unaligned_le32(baud, buf); | 388 | put_unaligned_le32(baud, buf); |
367 | } else { | 389 | else |
368 | /* | 390 | baud = pl2303_encode_baud_rate_divisor(buf, baud); |
369 | * Apparently the formula for higher speeds is: | ||
370 | * baudrate = 12M * 32 / (2^buf[1]) / buf[0] | ||
371 | */ | ||
372 | unsigned tmp = 12000000 * 32 / baud; | ||
373 | buf[3] = 0x80; | ||
374 | buf[2] = 0; | ||
375 | buf[1] = (tmp >= 256); | ||
376 | while (tmp >= 256) { | ||
377 | tmp >>= 2; | ||
378 | buf[1] <<= 1; | ||
379 | } | ||
380 | buf[0] = tmp; | ||
381 | } | ||
382 | 391 | ||
383 | /* Save resulting baud rate */ | 392 | /* Save resulting baud rate */ |
384 | tty_encode_baud_rate(tty, baud, baud); | 393 | tty_encode_baud_rate(tty, baud, baud); |