Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: serial: ch341: fix receiver regression

While assumed not to make a difference, not using the factor-2 prescaler
makes the receiver more susceptible to errors.

Specifically, there have been reports of problems with devices that
cannot generate a 115200 rate with a smaller error than 2.1% (e.g.
117647 bps). But this can also be reproduced with a low-speed RS232
tranceiver at 115200 when the input rate matches the nominal rate.

So whenever possible, enable the factor-2 prescaler and halve the
divisor in order to use settings closer to that of the previous
algorithm.

Fixes: 35714565089e ("USB: serial: ch341: reimplement line-speed handling")
Cc: stable <stable@vger.kernel.org> # 5.5
Reported-by: Jakub Nantl <jn@forever.cz>
Tested-by: Jakub Nantl <jn@forever.cz>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>

+10
+10
drivers/usb/serial/ch341.c
··· 205 205 16 * speed - 16 * CH341_CLKRATE / (clk_div * (div + 1))) 206 206 div++; 207 207 208 + /* 209 + * Prefer lower base clock (fact = 0) if even divisor. 210 + * 211 + * Note that this makes the receiver more tolerant to errors. 212 + */ 213 + if (fact == 1 && div % 2 == 0) { 214 + div /= 2; 215 + fact = 0; 216 + } 217 + 208 218 return (0x100 - div) << 8 | fact << 2 | ps; 209 219 } 210 220