Newer cp210x devices support higher line speeds than the older ones which supported a discrete set of speeds up to 921.6 kbaud. To support these higher speeds, we have for some time mapped speeds lower than 1 Mbaud to the speeds supported by older devices, while allowing the device to pick the closest possible rate for higher speeds (without trying to guess and report back what rate was actually chosen). As this implementation can lead to undefined behaviour for older devices which do not support the higher rates, let's use the later-added device-type detection to determine the maximum supported speed. This will also be useful when adding support for cp2102n which can handle rates up to 3 Mbaud. As per the data sheets the following maximum speeds are used cp2101 921.6 kbaud cp2102/3 1 Mbaud cp2104/8 2 Mbaud cp2105 - ECI port 2 Mbaud - SCI port 921.6 kbaud while keeping the maximum 2 Mbaud for unknown device types in order to avoid any regressions. Signed-off-by: Johan Hovold <johan@xxxxxxxxxx> --- drivers/usb/serial/cp210x.c | 41 ++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index e1a4d4b3d3aa..7772c4ce45a6 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -244,6 +244,7 @@ struct cp210x_serial_private { bool gpio_registered; #endif u8 partnum; + speed_t max_speed; }; struct cp210x_port_private { @@ -1067,19 +1068,20 @@ static speed_t cp210x_get_an205_rate(speed_t baud) static void cp210x_change_speed(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct cp210x_serial_private *priv = usb_get_serial_data(port->serial); u32 baud; baud = tty->termios.c_ospeed; /* This maps the requested rate to a rate valid on cp2102 or cp2103, - * or to an arbitrary rate in [1M,2M]. + * or to an arbitrary rate in [1M, max_speed] * * NOTE: B0 is not implemented. */ if (baud < 1000000) baud = cp210x_get_an205_rate(baud); - else if (baud > 2000000) - baud = 2000000; + else if (baud > priv->max_speed) + baud = priv->max_speed; dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud); if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) { @@ -1510,6 +1512,37 @@ static int cp210x_port_remove(struct usb_serial_port *port) return 0; } +static void cp210x_init_max_speed(struct usb_serial *serial) +{ + struct cp210x_serial_private *priv = usb_get_serial_data(serial); + speed_t max; + + switch (priv->partnum) { + case CP210X_PARTNUM_CP2101: + max = 921600; + break; + case CP210X_PARTNUM_CP2102: + case CP210X_PARTNUM_CP2103: + max = 1000000; + break; + case CP210X_PARTNUM_CP2104: + case CP210X_PARTNUM_CP2108: + max = 2000000; + break; + case CP210X_PARTNUM_CP2105: + if (cp210x_interface_num(serial) == 0) + max = 2000000; /* ECI */ + else + max = 921600; /* SCI */ + break; + default: + max = 2000000; + break; + } + + priv->max_speed = max; +} + static int cp210x_attach(struct usb_serial *serial) { int result; @@ -1530,6 +1563,8 @@ static int cp210x_attach(struct usb_serial *serial) usb_set_serial_data(serial, priv); + cp210x_init_max_speed(serial); + if (priv->partnum == CP210X_PARTNUM_CP2105) { result = cp2105_shared_gpio_init(serial); if (result < 0) { -- 2.18.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html