From: Johan Hovold <johan@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: Jonathan Olds <jontio@i4free.co.nz>,
Michael Dreher <michael@5dot1.de>,
linux-usb@vger.kernel.org
Subject: Re: [PATCH] USB: serial: ch341: reimplement line-speed handling
Date: Mon, 4 Nov 2019 13:08:10 +0100 [thread overview]
Message-ID: <20191104120810.GH3657@localhost> (raw)
In-Reply-To: <20191101172410.20419-1-johan@kernel.org>
On Fri, Nov 01, 2019 at 06:24:10PM +0100, Johan Hovold wrote:
> The current ch341 divisor algorithm was known to give inaccurate results
> for certain higher line speeds. Jonathan Olds <jontio@i4free.co.nz>
> investigated this, determined the basic equations used to derive the
> divisors and confirmed them experimentally [1].
>
> The equations Jonathan used could be generalised further to:
>
> baud = 48000000 / (2^(12 - 3 * ps - fact) * div), where
>
> 0 <= ps <= 3,
> 0 <= fact <= 1,
> 2 <= div <= 256 if fact = 0, or
> 9 <= div <= 256 if fact = 1
>
> which will also give better results for lower rates.
>
> Notably the error is reduced for the following standard rates:
>
> 1152000 (4.0% instead of 15% error)
> 921600 (0.16% instead of -7.5% error)
> 576000 (-0.80% instead of -5.6% error)
> 200 (0.16% instead of -0.69% error)
> 134 (-0.05% instead of -0.63% error)
> 110 (0.03% instead of -0.44% error)
>
> but also for many non-standard ones.
>
> The current algorithm also suffered from rounding issues (e.g. 2950000
> was rounded to 2 Mbaud instead of 3 Mbaud resulting in a -32% instead of
> 1.7% error).
>
> The new algorithm was inspired by the current vendor driver even if that
> one only handles two higher rates that require fact=1 by hard coding the
> corresponding divisors [2].
>
> Michael Dreher <michael@5dot1.de> also did a similar generalisation of
> Jonathan's work and has published his results with a very good summary
> that provides further insights into how this device works [3].
>
> [1] https://lkml.kernel.org/r/000001d51f34$bad6afd0$30840f70$@co.nz
> [2] http://www.wch.cn/download/CH341SER_LINUX_ZIP.html
> [3] https://github.com/nospam2000/ch341-baudrate-calculation
>
> Reported-by: Jonathan Olds <jontio@i4free.co.nz>
> Tested-by: Jonathan Olds <jontio@i4free.co.nz>
> Cc: Michael Dreher <michael@5dot1.de>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/usb/serial/ch341.c | 97 +++++++++++++++++++++++++++++---------
> 1 file changed, 75 insertions(+), 22 deletions(-)
I've applied this one for 5.5 now (not 5.4 as I mistakingly said earlier).
Johan
prev parent reply other threads:[~2019-11-04 12:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-01 17:24 [PATCH] USB: serial: ch341: reimplement line-speed handling Johan Hovold
2019-11-04 12:08 ` Johan Hovold [this message]
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=20191104120810.GH3657@localhost \
--to=johan@kernel.org \
--cc=jontio@i4free.co.nz \
--cc=linux-usb@vger.kernel.org \
--cc=michael@5dot1.de \
/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).