USB: pl2303: use direct baud-rate encoding when possible
Use direct baud-rate encoding rather than divisors for supported baud
rates.
This restores the way baud rates were set prior to commit 8d48fdf689
("USB: PL2303: correctly handle baudrates above 115200") which added
divisor encoding, but also switched to the new encoding method for all
baudrates above 115200.
As noted by Frank Schäfer <fschaefer.oss@googlemail.com>, baud rate 500k
was later errounously added to the supported baud-rate table although
it can only be set using divisors.
Note that the current implementation could easily be extended to support
arbitrary non-standard baud rates using divisors (e.g. by falling back
to divisors when the table lookup fails).
Cc: Frank Schäfer <fschaefer.oss@googlemail.com>
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
20b4c78719
commit
5d85045f4b
1 changed files with 13 additions and 8 deletions
|
@ -312,14 +312,15 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the nearest supported baud rate.
|
* Returns the nearest supported baud rate that can be set directly without
|
||||||
|
* using divisors.
|
||||||
*/
|
*/
|
||||||
static speed_t pl2303_get_supported_baud_rate(speed_t baud)
|
static speed_t pl2303_get_supported_baud_rate(speed_t baud)
|
||||||
{
|
{
|
||||||
static const speed_t baud_sup[] = {
|
static const speed_t baud_sup[] = {
|
||||||
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,
|
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,
|
||||||
14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,
|
14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,
|
||||||
500000, 614400, 921600, 1228800, 2457600, 3000000, 6000000
|
614400, 921600, 1228800, 2457600, 3000000, 6000000
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
@ -379,6 +380,7 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
|
||||||
{
|
{
|
||||||
struct usb_serial *serial = port->serial;
|
struct usb_serial *serial = port->serial;
|
||||||
struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
|
struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
|
||||||
|
speed_t baud_sup;
|
||||||
speed_t baud;
|
speed_t baud;
|
||||||
|
|
||||||
baud = tty_get_baud_rate(tty);
|
baud = tty_get_baud_rate(tty);
|
||||||
|
@ -388,14 +390,17 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
|
||||||
|
|
||||||
if (spriv->type->max_baud_rate)
|
if (spriv->type->max_baud_rate)
|
||||||
baud = min_t(speed_t, baud, spriv->type->max_baud_rate);
|
baud = min_t(speed_t, baud, spriv->type->max_baud_rate);
|
||||||
|
/*
|
||||||
|
* Set baud rate to nearest supported value.
|
||||||
|
*
|
||||||
|
* NOTE: Baud rate 500k can only be set using divisors.
|
||||||
|
*/
|
||||||
|
baud_sup = pl2303_get_supported_baud_rate(baud);
|
||||||
|
|
||||||
/* Set baud rate to nearest supported value. */
|
if (baud == 500000)
|
||||||
baud = pl2303_get_supported_baud_rate(baud);
|
|
||||||
|
|
||||||
if (baud <= 115200)
|
|
||||||
baud = pl2303_encode_baud_rate_direct(buf, baud);
|
|
||||||
else
|
|
||||||
baud = pl2303_encode_baud_rate_divisor(buf, baud);
|
baud = pl2303_encode_baud_rate_divisor(buf, baud);
|
||||||
|
else
|
||||||
|
baud = pl2303_encode_baud_rate_direct(buf, baud_sup);
|
||||||
|
|
||||||
/* Save resulting baud rate */
|
/* Save resulting baud rate */
|
||||||
tty_encode_baud_rate(tty, baud, baud);
|
tty_encode_baud_rate(tty, baud, baud);
|
||||||
|
|
Loading…
Reference in a new issue