aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2013-12-29 13:23:11 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-01-03 15:31:48 -0500
commit59afe10e8dd33d26f8c2ae7572f9023044e71bab (patch)
tree524cc74abb81ffd5788470b2c875fba5fba29fcd /drivers/usb/serial
parent79816824c1ae73542d9523283ce353142b67563e (diff)
USB: pl2303: refactor baud-rate table lookup
Refactor supported baud-rate table lookup. 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.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 8d792afbe27f..9a95b92310f2 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -311,31 +311,19 @@ static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
311 return retval; 311 return retval;
312} 312}
313 313
314static void pl2303_encode_baud_rate(struct tty_struct *tty, 314/*
315 struct usb_serial_port *port, 315 * Returns the nearest supported baud rate.
316 u8 buf[4]) 316 */
317static speed_t pl2303_get_supported_baud_rate(speed_t baud)
317{ 318{
318 const speed_t baud_sup[] = { 75, 150, 300, 600, 1200, 1800, 2400, 3600, 319 static const speed_t baud_sup[] = {
319 4800, 7200, 9600, 14400, 19200, 28800, 38400, 320 75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,
320 57600, 115200, 230400, 460800, 500000, 614400, 321 14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,
321 921600, 1228800, 2457600, 3000000, 6000000 }; 322 500000, 614400, 921600, 1228800, 2457600, 3000000, 6000000
323 };
322 324
323 struct usb_serial *serial = port->serial; 325 unsigned i;
324 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
325 speed_t baud;
326 int i;
327 326
328 /*
329 * NOTE: Only the values defined in baud_sup are supported!
330 * => if unsupported values are set, the PL2303 seems to use
331 * 9600 baud (at least my PL2303X always does)
332 */
333 baud = tty_get_baud_rate(tty);
334 dev_dbg(&port->dev, "baud requested = %u\n", baud);
335 if (!baud)
336 return;
337
338 /* Set baud rate to nearest supported value */
339 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) { 327 for (i = 0; i < ARRAY_SIZE(baud_sup); ++i) {
340 if (baud_sup[i] > baud) 328 if (baud_sup[i] > baud)
341 break; 329 break;
@@ -348,6 +336,29 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
348 else 336 else
349 baud = baud_sup[i]; 337 baud = baud_sup[i];
350 338
339 return baud;
340}
341
342static void pl2303_encode_baud_rate(struct tty_struct *tty,
343 struct usb_serial_port *port,
344 u8 buf[4])
345{
346 struct usb_serial *serial = port->serial;
347 struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
348 speed_t baud;
349
350 baud = tty_get_baud_rate(tty);
351 dev_dbg(&port->dev, "baud requested = %u\n", baud);
352 if (!baud)
353 return;
354 /*
355 * Set baud rate to nearest supported value.
356 *
357 * NOTE: If unsupported values are set directly, the PL2303 seems to
358 * use 9600 baud.
359 */
360 baud = pl2303_get_supported_baud_rate(baud);
361
351 if (spriv->type->max_baud_rate) 362 if (spriv->type->max_baud_rate)
352 baud = min_t(speed_t, baud, spriv->type->max_baud_rate); 363 baud = min_t(speed_t, baud, spriv->type->max_baud_rate);
353 364