From patchwork Wed Jul 18 12:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10532329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D10260633 for ; Wed, 18 Jul 2018 12:25:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7282328DC4 for ; Wed, 18 Jul 2018 12:25:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66D8229076; Wed, 18 Jul 2018 12:25:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F327728DC4 for ; Wed, 18 Jul 2018 12:25:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731109AbeGRNDN (ORCPT ); Wed, 18 Jul 2018 09:03:13 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:43782 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730889AbeGRNDM (ORCPT ); Wed, 18 Jul 2018 09:03:12 -0400 Received: by mail-lf0-f66.google.com with SMTP id m12-v6so3307603lfc.10 for ; Wed, 18 Jul 2018 05:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=OV54HMXMwm5O7my66QceiBjrb+bEllNqSjhcVDQ0Uc4=; b=ecrintW/8Rhh8QUcjNxv56Bqvr3F1kMO5mDrcyZry5+MD6RHV5pSYdjlWDe7OBcs9w QdxxZ4poVCGl3m1CbRPxirJkSmCxSXjMXFoLXSOOxkh7kYhIGjk31IugCpkttYe33zZ/ IA+tejDTrmtU2KI/MoKUKqgkYGPf7J/GjYBU2Y/PtRjwWZpokRoIZbgTywf6ohhMl2Of R5YwOxdwoOBNJg7FE2IxS6hlsHQ+wYUt5zLwW6Krg17BPKG8SruVdj5CZb+7cjm6Fq8U hUSC8VV1qAA/6TLAWI5/xSau9g7gt2fOd7eYnUjasIGOwS0tig0hve4vqs9rwYrtp9rR Jk0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=OV54HMXMwm5O7my66QceiBjrb+bEllNqSjhcVDQ0Uc4=; b=jEcitAlWAd1mXDT5MYZvqEd8HdvTfkjUntmQ/OR0ymn+Clh486DgEeEsKFiUpCm8vm fqaCGH+ndpuSMKaXIQo/Vjyb/UdUY73UKno4hMP2lgGn0pQfJli7cDnnVj9xPhJQws07 gQTFRzHyuogDBbGAP9h7vTpQ2ujhc1J0P/5ZV66c0zaI2SPJ35IDJnkwLQAZXGWKLljO k786JLVAjcwVYsijOXjoNuwQD1T3y93kIaxW5AeDYwU2dE/Lo35ycIqoWNkLtcSIDFr6 ElTQh84kDQJvo2nJbfgISeiCax40HUdxe+ETroJpJnnzfvMLiwL2E3hliZrxO1QVVKuI ONpQ== X-Gm-Message-State: AOUpUlFz6D7qX7QbvZNNuHaTh/D3AkW3zpqAJS9719o7a6CCHl76mzhh 60P9NxAm2jdY1Jpp0b3TqS1ksfTu X-Google-Smtp-Source: AAOMgpfuXJ2tMgmhfP4mI9b4d2Q74PPsS1W7a9DIG0t20cHs2n6JTft76wRB4v3J00GbDfjJYEUvPQ== X-Received: by 2002:a19:10c4:: with SMTP id 65-v6mr4132958lfq.113.1531916730270; Wed, 18 Jul 2018 05:25:30 -0700 (PDT) Received: from xi.terra (c-8bb2e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.178.139]) by smtp.gmail.com with ESMTPSA id f2-v6sm536096lfb.11.2018.07.18.05.25.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 05:25:28 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fflW8-0003th-Hg; Wed, 18 Jul 2018 14:25:16 +0200 From: Johan Hovold To: Johan Hovold Cc: Greg Kroah-Hartman , Karoly Pados , linux-usb@vger.kernel.org Subject: [PATCH 2/5] USB: serial: cp210x: honour device-type maximum line speed Date: Wed, 18 Jul 2018 14:24:58 +0200 Message-Id: <20180718122501.14926-3-johan@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180718122501.14926-1-johan@kernel.org> References: <20180718122501.14926-1-johan@kernel.org> Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Greg Kroah-Hartman --- 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 1b380309f653..4281f2bfe0e1 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -229,6 +229,7 @@ struct cp210x_serial_private { bool gpio_registered; #endif u8 partnum; + speed_t max_speed; }; struct cp210x_port_private { @@ -1052,19 +1053,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)) { @@ -1495,6 +1497,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; @@ -1515,6 +1548,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) {