Skip to content

Commit

Permalink
USB: pl2303: use divisors for unsupported baud rates
Browse files Browse the repository at this point in the history
Use direct method for supported baud rates, otherwise use divisors.
Limit baud rate to 12 Mbaud with HX type.

This change has been tested to work with PL-2303HX at 115200, 500000,
1000000, 2000000, 2500000, 3000000 and 4000000 baud rates.

Signed-off-by: Lauri Hintsala <lauri.hintsala@bluegiga.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
  • Loading branch information
Lauri Hintsala authored and Johan Hovold committed Sep 1, 2014
1 parent 69e273c commit 399aa9a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions drivers/usb/serial/pl2303.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
.max_baud_rate = 1228800,
.quirks = PL2303_QUIRK_LEGACY,
},
[TYPE_HX] = {
.max_baud_rate = 12000000,
},
};

static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
Expand Down Expand Up @@ -395,16 +398,14 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
if (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.
* Use direct method for supported baud rates, otherwise use divisors.
*/
baud_sup = pl2303_get_supported_baud_rate(baud);

if (baud == 500000)
baud = pl2303_encode_baud_rate_divisor(buf, baud);
if (baud == baud_sup)
baud = pl2303_encode_baud_rate_direct(buf, baud);
else
baud = pl2303_encode_baud_rate_direct(buf, baud_sup);
baud = pl2303_encode_baud_rate_divisor(buf, baud);

/* Save resulting baud rate */
tty_encode_baud_rate(tty, baud, baud);
Expand Down

0 comments on commit 399aa9a

Please sign in to comment.