From patchwork Thu Jul 5 14:49:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10509555 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 1E3ED60116 for ; Thu, 5 Jul 2018 14:51:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DE4929183 for ; Thu, 5 Jul 2018 14:51:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 025CA2918C; Thu, 5 Jul 2018 14:51:37 +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 8E58229183 for ; Thu, 5 Jul 2018 14:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753749AbeGEOvb (ORCPT ); Thu, 5 Jul 2018 10:51:31 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:43696 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753577AbeGEOtn (ORCPT ); Thu, 5 Jul 2018 10:49:43 -0400 Received: by mail-lf0-f67.google.com with SMTP id m12-v6so7189784lfc.10 for ; Thu, 05 Jul 2018 07:49:42 -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=/7XYrpqLy06tQz8GvotnygjI7iszU8qoOdf6YVPKI+c=; b=dq4uCgDpn6KT7m41yPInvrq9u1bEHSjz5tEnXh+ZjHwoFpvlxapJsLs+FOSdGuSNyk r1B7EPvmDlgt4AU5uJCyymd3L5djfsBrxJZ4mVv/C5LOOUd3IUP6L3vJa+5kTxM9EjLo BKZM4McXmfLXq4L3VBY2j2p9IE0DjEGVabxQ6t2p7Wh+F1aPJzb34oZaipZOaC9z9DkG 1vaep58f0LZKvCJw2viOAnERLXPCGybnTSQr4NTCF7WONKJoalpfjvW3IYyOiZMjhrEi gy4i0qcB2XqCbbL08p3pfhXZN8dDRn9nGNl4icDMmvcsT09CcaQAjMvxiDhwFOon878u Lo2g== 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=/7XYrpqLy06tQz8GvotnygjI7iszU8qoOdf6YVPKI+c=; b=iATPo4Ep+1k5NXvhgm5gk6bUQgnFvZTCycHiPJgoGyr3ni5itFn17EF87px6v5/f1o SIbybRLuby2de1CQPT/l2mr+kyorLNfQ+EayQ5P2AionlDPxsI2BAM/bi+9aNhz6Kohd cQC6MTe++oG4fnmagYLEj52RITPs/jpaZfuMdQx8PoVxaf950MIkw7Gb4fpIEQJRTE7B RyoqsorWgIkNpe2NZrPau8FMGMwq2xnNDZkbdp9eWHqVGy4zw0Svdm9aaV+ICnCesMyl HbrSSGJLxJlDI/dqFLuyVli1g4npWwkVlArS0Ce/LJDcSU9/JS3UGSnOtLK7xtQ3h/oN g8mA== X-Gm-Message-State: APt69E1xx8dhQof2sLgiZiws4oKy5aK39vaTRq2S4auUX2INsip61m94 QcIMKQB6kMA7KG7ZrZBfDOs= X-Google-Smtp-Source: AAOMgpcGH9mKrsr10Kxgr8IznFp2bgW2y0mrDlIP+D/nQNT5z9/Su4lIJIgu7X5RK4Wx8htenIpBIg== X-Received: by 2002:a19:4d0a:: with SMTP id a10-v6mr4436433lfb.5.1530802181526; Thu, 05 Jul 2018 07:49:41 -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 h137-v6sm1484078lfg.23.2018.07.05.07.49.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jul 2018 07:49:38 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1fb5ZZ-000305-IY; Thu, 05 Jul 2018 16:49:29 +0200 From: Johan Hovold To: Johan Hovold Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, Karoly Pados Subject: [PATCH 2/2] USB: serial: cp210x: honour device-type maximum line speed Date: Thu, 5 Jul 2018 16:49:09 +0200 Message-Id: <20180705144909.11483-3-johan@kernel.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180705144909.11483-1-johan@kernel.org> References: <20180705144909.11483-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 --- 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) {