Skip to content

Commit

Permalink
USB: pl2303: add helper function for direct baud-rate encoding
Browse files Browse the repository at this point in the history
Add helper function for direct baud-rate encoding.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Johan Hovold authored and Greg Kroah-Hartman committed Jan 3, 2014
1 parent c82c6d4 commit 20b4c78
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions drivers/usb/serial/pl2303.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ static speed_t pl2303_get_supported_baud_rate(speed_t baud)
return baud;
}

/*
* NOTE: If unsupported baud rates are set directly, the PL2303 seems to
* use 9600 baud.
*/
static speed_t pl2303_encode_baud_rate_direct(unsigned char buf[4],
speed_t baud)
{
put_unaligned_le32(baud, buf);

return baud;
}

static speed_t pl2303_encode_baud_rate_divisor(unsigned char buf[4],
speed_t baud)
{
Expand Down Expand Up @@ -376,16 +388,12 @@ 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: If unsupported values are set directly, the PL2303 seems to
* use 9600 baud.
*/

/* Set baud rate to nearest supported value. */
baud = pl2303_get_supported_baud_rate(baud);

if (baud <= 115200)
put_unaligned_le32(baud, buf);
baud = pl2303_encode_baud_rate_direct(buf, baud);
else
baud = pl2303_encode_baud_rate_divisor(buf, baud);

Expand Down

0 comments on commit 20b4c78

Please sign in to comment.