From patchwork Wed Feb 6 08:56:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johanna Abrahamsson X-Patchwork-Id: 10798889 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9E1C13B5 for ; Wed, 6 Feb 2019 08:56:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C31EF2AA72 for ; Wed, 6 Feb 2019 08:56:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B53342AA95; Wed, 6 Feb 2019 08:56:21 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 087C82AA72 for ; Wed, 6 Feb 2019 08:56:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728460AbfBFI4U (ORCPT ); Wed, 6 Feb 2019 03:56:20 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:47003 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728278AbfBFI4U (ORCPT ); Wed, 6 Feb 2019 03:56:20 -0500 Received: by mail-lj1-f194.google.com with SMTP id v15-v6so5270276ljh.13 for ; Wed, 06 Feb 2019 00:56:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:in-reply-to:user-agent; bh=a3pKq2VOgiDL4nWXDUqqlO1kEtRgUxck4w0Kwro+890=; b=CUcQi3cyOCSDqLYERpGogexrH2P9mWbuLTnztNTP/YEAxpOkYe5sr/mkpc94AjV1bQ hip7/Va0Nq6hakxdI3TeX5a1HGkmUcr4w9ak16PijtRJpN7iXKO+9pVrj7Uh8aWI9g10 9aRXVQThmpFL3ZK/Nok53UdEnArp0vlX+RjBKrvuNE12nXaENlMJtB11xRN11JAGu82R +ydbhVlXxr/xA7zNrud5eUJWw75kjT6/xm3nGsiBl20n2qrcdby+f44LCoBjnSqBWcPm SwpRFQzBA3QE0N4MdZCsDbq9KoN2scMnysI6Dzkr/qaOLcsOhCf2rc+PtU0bVb8JHwQk vAoA== X-Gm-Message-State: AHQUAuYWOAsSXQR2y6RAIA4MP51JwAzS0QPi6lSjdRzhNG5RnbdbE8r9 jm65GenB9Oit7QqHECa/BRyJ8dvQ X-Google-Smtp-Source: AHgI3IYw651Swumpa+PWd5tfgRcwNQHKk63Inu+TSIvc8fwHqCjIcr7oiTyeEOwNx/P/z2dcm4hFew== X-Received: by 2002:a2e:8992:: with SMTP id c18-v6mr5761599lji.17.1549443377663; Wed, 06 Feb 2019 00:56:17 -0800 (PST) Received: from fedora-21-dvm ([194.103.240.26]) by smtp.gmail.com with ESMTPSA id r199sm1499384lfr.77.2019.02.06.00.56.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Feb 2019 00:56:16 -0800 (PST) Date: Wed, 6 Feb 2019 09:56:15 +0100 From: Johanna Abrahamsson To: linux-usb@vger.kernel.org Cc: Johan Hovold Subject: [PATCH v2] USB: serial: cp210x: add minimun baud rate for CP2105 SCI Message-ID: <20190206085612.GA2278@fedora-21-dvm> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190204160129.GG4686@localhost> User-Agent: Mutt/1.5.23 (2014-03-12) 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 From: Johanna Abrahamsson This patch adds minimum baud rate to the cp210x driver. According to the datasheet for CP2105, the SCI supports 2400 as the lowest baud rate. As this is not heeded in the current code, an error message 'failed set req 0x1e size 4 status: -32' when trying to set a lower baud rate such as 300. The other cp210x models to date supports a minimum baud rate of 300. Signed-off-by: Johanna Abrahamsson --- drivers/usb/serial/cp210x.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 260c875dd263..ceff735e961c 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -245,6 +245,7 @@ struct cp210x_serial_private { u8 gpio_input; #endif u8 partnum; + speed_t min_speed; speed_t max_speed; bool use_actual_rate; }; @@ -1078,8 +1079,6 @@ static speed_t cp210x_get_actual_rate(struct usb_serial *serial, speed_t baud) unsigned int prescale = 1; unsigned int div; - baud = clamp(baud, 300u, priv->max_speed); - if (baud <= 365) prescale = 4; @@ -1122,7 +1121,7 @@ static void cp210x_change_speed(struct tty_struct *tty, struct cp210x_serial_private *priv = usb_get_serial_data(serial); u32 baud; - baud = tty->termios.c_ospeed; + baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed); /* * This maps the requested rate to the actual rate, a valid rate on @@ -1134,8 +1133,6 @@ static void cp210x_change_speed(struct tty_struct *tty, baud = cp210x_get_actual_rate(serial, baud); else if (baud < 1000000) baud = cp210x_get_an205_rate(baud); - 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)) { @@ -1797,28 +1794,35 @@ static void cp210x_init_max_speed(struct usb_serial *serial) { struct cp210x_serial_private *priv = usb_get_serial_data(serial); bool use_actual_rate = false; + speed_t min; speed_t max; switch (priv->partnum) { case CP210X_PARTNUM_CP2101: + min = 300; max = 921600; break; case CP210X_PARTNUM_CP2102: case CP210X_PARTNUM_CP2103: + min = 300; max = 1000000; break; case CP210X_PARTNUM_CP2104: use_actual_rate = true; + min = 300; max = 2000000; break; case CP210X_PARTNUM_CP2108: + min = 300; max = 2000000; break; case CP210X_PARTNUM_CP2105: if (cp210x_interface_num(serial) == 0) { use_actual_rate = true; + min = 300; max = 2000000; /* ECI */ } else { + min = 2400; max = 921600; /* SCI */ } break; @@ -1826,13 +1830,16 @@ static void cp210x_init_max_speed(struct usb_serial *serial) case CP210X_PARTNUM_CP2102N_QFN24: case CP210X_PARTNUM_CP2102N_QFN20: use_actual_rate = true; + min = 300; max = 3000000; break; default: + min = 300; max = 2000000; break; } + priv->min_speed = min; priv->max_speed = max; priv->use_actual_rate = use_actual_rate; }