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>
This commit is contained in:
parent
871996ede1
commit
c82c6d45a2
1 changed files with 25 additions and 16 deletions
|
@ -339,6 +339,28 @@ static speed_t pl2303_get_supported_baud_rate(speed_t baud)
|
||||||
return baud;
|
return baud;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static speed_t pl2303_encode_baud_rate_divisor(unsigned char buf[4],
|
||||||
|
speed_t baud)
|
||||||
|
{
|
||||||
|
unsigned int tmp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Apparently the formula is:
|
||||||
|
* baudrate = 12M * 32 / (2^buf[1]) / buf[0]
|
||||||
|
*/
|
||||||
|
tmp = 12000000 * 32 / baud;
|
||||||
|
buf[3] = 0x80;
|
||||||
|
buf[2] = 0;
|
||||||
|
buf[1] = (tmp >= 256);
|
||||||
|
while (tmp >= 256) {
|
||||||
|
tmp >>= 2;
|
||||||
|
buf[1] <<= 1;
|
||||||
|
}
|
||||||
|
buf[0] = tmp;
|
||||||
|
|
||||||
|
return baud;
|
||||||
|
}
|
||||||
|
|
||||||
static void pl2303_encode_baud_rate(struct tty_struct *tty,
|
static void pl2303_encode_baud_rate(struct tty_struct *tty,
|
||||||
struct usb_serial_port *port,
|
struct usb_serial_port *port,
|
||||||
u8 buf[4])
|
u8 buf[4])
|
||||||
|
@ -362,23 +384,10 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
|
||||||
*/
|
*/
|
||||||
baud = pl2303_get_supported_baud_rate(baud);
|
baud = pl2303_get_supported_baud_rate(baud);
|
||||||
|
|
||||||
if (baud <= 115200) {
|
if (baud <= 115200)
|
||||||
put_unaligned_le32(baud, buf);
|
put_unaligned_le32(baud, buf);
|
||||||
} else {
|
else
|
||||||
/*
|
baud = pl2303_encode_baud_rate_divisor(buf, baud);
|
||||||
* Apparently the formula for higher speeds is:
|
|
||||||
* baudrate = 12M * 32 / (2^buf[1]) / buf[0]
|
|
||||||
*/
|
|
||||||
unsigned tmp = 12000000 * 32 / baud;
|
|
||||||
buf[3] = 0x80;
|
|
||||||
buf[2] = 0;
|
|
||||||
buf[1] = (tmp >= 256);
|
|
||||||
while (tmp >= 256) {
|
|
||||||
tmp >>= 2;
|
|
||||||
buf[1] <<= 1;
|
|
||||||
}
|
|
||||||
buf[0] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Save resulting baud rate */
|
/* Save resulting baud rate */
|
||||||
tty_encode_baud_rate(tty, baud, baud);
|
tty_encode_baud_rate(tty, baud, baud);
|
||||||
|
|
Loading…
Add table
Reference in a new issue