From: Johan Hovold <johan@kernel.org>
To: Michael Hanselmann <public@hansmi.ch>
Cc: linux-usb@vger.kernel.org, Johan Hovold <johan@kernel.org>,
Michael Dreher <michael@5dot1.de>,
Jonathan Olds <jontio@i4free.co.nz>
Subject: Re: [PATCH v2 3/6] USB: serial: ch341: Limit prescaler on quirky chips
Date: Wed, 27 May 2020 15:16:58 +0200 [thread overview]
Message-ID: <20200527131658.GJ5276@localhost> (raw)
In-Reply-To: <20200514141743.GE25962@localhost>
On Thu, May 14, 2020 at 04:17:43PM +0200, Johan Hovold wrote:
> On Tue, Mar 31, 2020 at 11:37:19PM +0000, Michael Hanselmann wrote:
> From ea23730616b6406101d4efeb12e1ae2312dd20c9 Mon Sep 17 00:00:00 2001
> From: Johan Hovold <johan@kernel.org>
> Date: Thu, 14 May 2020 11:36:45 +0200
> Subject: [PATCH] USB: serial: ch341: fix lockup of devices with limited
> prescaler
>
> Michael Hanselmann reports that
>
> [a] subset of all CH341 devices stop responding to bulk
> transfers, usually after the third byte, when the highest
> prescaler bit (0b100) is set. There is one exception, namely a
> prescaler of exactly 0b111 (fact=1, ps=3).
>
> Fix this by forcing a lower base clock (fact = 0) whenever needed.
>
> This specifically makes the standard rates 110, 134 and 200 bps work
> again with these devices.
>
> Fixes: 35714565089e ("USB: serial: ch341: reimplement line-speed handling")
> Cc: stable <stable@vger.kernel.org> # 5.5
> Reported-by: Michael Hanselmann <public@hansmi.ch>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/usb/serial/ch341.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
> index f2b93f4554a7..89675ee29645 100644
> --- a/drivers/usb/serial/ch341.c
> +++ b/drivers/usb/serial/ch341.c
> @@ -73,6 +73,8 @@
> #define CH341_LCR_CS6 0x01
> #define CH341_LCR_CS5 0x00
>
> +#define CH341_QUIRK_LIMITED_PRESCALER BIT(0)
> +
> static const struct usb_device_id id_table[] = {
> { USB_DEVICE(0x4348, 0x5523) },
> { USB_DEVICE(0x1a86, 0x7523) },
> @@ -160,9 +162,11 @@ static const speed_t ch341_min_rates[] = {
> * 2 <= div <= 256 if fact = 0, or
> * 9 <= div <= 256 if fact = 1
> */
> -static int ch341_get_divisor(speed_t speed)
> +static int ch341_get_divisor(struct ch341_private *priv)
> {
> unsigned int fact, div, clk_div;
> + speed_t speed = priv->baud_rate;
> + bool force_fact0 = false;
> int ps;
>
> /*
> @@ -188,8 +192,12 @@ static int ch341_get_divisor(speed_t speed)
> clk_div = CH341_CLK_DIV(ps, fact);
> div = CH341_CLKRATE / (clk_div * speed);
>
> + /* Some devices require a lower base clock if ps < 3. */
> + if (ps < 3 && (priv->quirks & CH341_QUIRK_LIMITED_PRESCALER))
> + force_fact0 = true;
> +
> /* Halve base clock (fact = 0) if required. */
> - if (div < 9 || div > 255) {
> + if (div < 9 || div > 255 || force_fact0) {
> div /= 2;
> clk_div *= 2;
> fact = 0;
> @@ -228,7 +236,7 @@ static int ch341_set_baudrate_lcr(struct usb_device *dev,
> if (!priv->baud_rate)
> return -EINVAL;
>
> - val = ch341_get_divisor(priv->baud_rate);
> + val = ch341_get_divisor(priv);
> if (val < 0)
> return -EINVAL;
>
> @@ -333,6 +341,7 @@ static int ch341_detect_quirks(struct usb_serial_port *port)
> CH341_REG_BREAK, 0, buffer, size, DEFAULT_TIMEOUT);
> if (r == -EPIPE) {
> dev_dbg(&port->dev, "break control not supported\n");
> + quirks = CH341_QUIRK_LIMITED_PRESCALER;
> r = 0;
> goto out;
> }
I've applied the above fix on top of your quirk-detection patch so that
we can get this into 5.8 and backported to stable.
Johan
next prev parent reply other threads:[~2020-05-27 13:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-31 23:37 [PATCH v2 0/6] USB: serial: ch341: Add support for limited chips (was: Add support for HL340 devices) Michael Hanselmann
2020-03-31 23:37 ` [PATCH v2 1/6] USB: serial: ch341: Reduce special cases in clock calculation Michael Hanselmann
2020-03-31 23:37 ` [PATCH v2 2/6] USB: serial: ch341: Add basis for quirk detection Michael Hanselmann
2020-05-14 14:09 ` Johan Hovold
2020-03-31 23:37 ` [PATCH v2 3/6] USB: serial: ch341: Limit prescaler on quirky chips Michael Hanselmann
2020-05-14 14:17 ` Johan Hovold
2020-05-27 13:16 ` Johan Hovold [this message]
2020-05-27 15:41 ` Michael Hanselmann
2020-05-29 7:15 ` Johan Hovold
2020-03-31 23:37 ` [PATCH v2 4/6] USB: serial: ch341: Name prescaler, divisor registers Michael Hanselmann
2020-05-14 14:24 ` Johan Hovold
2020-05-27 20:59 ` Michael Hanselmann
2020-06-29 9:51 ` Johan Hovold
2020-03-31 23:37 ` [PATCH v2 5/6] USB: serial: ch341: Compute minimum baud rate Michael Hanselmann
2020-05-27 22:19 ` Michael Hanselmann
2020-06-30 9:57 ` Johan Hovold
2020-03-31 23:37 ` [PATCH v2 6/6] USB: serial: ch341: Simulate break condition if not supported Michael Hanselmann
2020-05-14 14:47 ` Johan Hovold
2020-05-27 22:21 ` Michael Hanselmann
2020-06-30 11:39 ` Johan Hovold
2020-07-04 18:25 ` Michael Hanselmann
2020-07-06 9:31 ` Johan Hovold
2020-05-14 14:02 ` [PATCH v2 0/6] USB: serial: ch341: Add support for limited chips (was: Add support for HL340 devices) Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200527131658.GJ5276@localhost \
--to=johan@kernel.org \
--cc=jontio@i4free.co.nz \
--cc=linux-usb@vger.kernel.org \
--cc=michael@5dot1.de \
--cc=public@hansmi.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).