Re: ch341

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 12, 2016 at 08:03:03AM -0800, Russell Senior wrote:
> On Mon, Dec 12, 2016 at 7:54 AM, Johan Hovold <johan@xxxxxxxxxx> wrote:
> > On Mon, Dec 12, 2016 at 07:51:59AM -0800, Russell Senior wrote:
> >> On Mon, Dec 12, 2016 at 7:40 AM, Johan Hovold <johan@xxxxxxxxxx> wrote:
> >> > On Mon, Dec 12, 2016 at 07:09:34AM -0800, Russell Senior wrote:
> >> >> On Mon, Dec 12, 2016 at 1:54 AM, Johan Hovold <johan@xxxxxxxxxx> wrote:
> >> >>
> >> >> > Ok, so maybe your device simply does not support changing the line
> >> >> > settings more than once. That is, the initial settings chosen are used
> >> >> > until re-connected. This would seem to be in accordance with a comment
> >> >> > found in one of the out-of-tree drivers floating around (and which at
> >> >> > least I hoped would no longer be an issue with the new way of changing
> >> >> > the settings).
> >> >> >
> >> >> > If you connect the ch340 you have in loopback mode, with the removed
> >> >> > initial LCR write that fixed the 5-bit behaviour, can you get that
> >> >> > behaviour back by setting 5-bit word size after opening the port? (This
> >> >> > was what I was going for with my original question above.).
> >> >>
> >> >> With minicom configured with 5N1 (that is, 5-bit mode), loopback looks
> >> >> normal.  I type an 'a' and I get and 'a' back.  Likewise, I type an
> >> >> 'A' and I get an 'A' back.  I used a saved .minicom.dfl file to
> >> >> configure the port.
> >> >
> >> > Ok, so that seems to confirm the suspicion that changing settings after
> >> > the initial configuration is failing (even though the device does indeed
> >> > support 5-bit mode).
> >> >
> >> > Could you try to verify if that applies to the baud rate as well? That
> >> > is, can you switch between say 9600 and 115200 after opening the port
> >> > and verify that against the pl2303?
> >> >
> >> > Still using usb-linus with the first LCR write removed.
> >>
> >> I can change the baud rate on the ch341 and make it not work with the
> >> pl2303 (e.g. I send an 'A' from the pl2030 and get an 0xff on the
> >> ch341, and vice versa), then harmonize the baud rate again and it
> >> works again.  Changing baud rate seems to work.
> >
> > That's good. And just to confirm: you managed to get characters through
> > at both rates?
> 
> Yes, indeed.
> 
> When the baud rates match (tested 9600 and 115200), characters arrive
> as expected in both directions.

Can you try also the below diagnostics patch on top of usb-next (not
usb-linus this time)?

It seems we should be able to revert to setting the divisors and lcr
directly for all CH340 devices, while using the new method for CH341
only (which requires it).

Just want to make sure that keeping a common init sequence would still
work first.

Note that I don't expect you to be able to change word size, but
hopefully a default 8N1 will work while the baud rate would be
configurable.

Thanks,
Johan


>From 0510aa1f3aca5a2230bbd3d281b534a79ca021ee Mon Sep 17 00:00:00 2001
From: Johan Hovold <johan@xxxxxxxxxx>
Date: Fri, 9 Dec 2016 13:45:59 +0100
Subject: [PATCH] USB: serial: ch341: revert to setting divisors and lcr
 directly

Change the initial LCR setting to 8N1 and enable rx and tx.

This should have not effect as the LCR is again later updated at open,
but let's try anyway since we have gotten reports about ch341-devices
that appear to be stuck with 5-bit words.

Also try reverting to setting the divisor and lcr directly to try to
determine how best to enable support for some quirky CH340 devices.

Not-Yet-Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
 drivers/usb/serial/ch341.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 2597b83a8ae2..8e25b052ace5 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -156,9 +156,13 @@ static int ch341_init_set_baudrate(struct usb_device *dev,
 	factor = 0x10000 - factor;
 	a = (factor & 0xff00) | divisor;
 
-	/* 0x9c is "enable SFR_UART Control register and timer" */
-	r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT,
-			      0x9c | (ctrl << 8), a | 0x80);
+	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x1312, a);
+	if (r)
+		return r;
+
+	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, ctrl);
+	if (r)
+		return r;
 
 	return r;
 }
@@ -223,16 +227,12 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
 	if (r < 0)
 		goto out;
 
-	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, 0x0050);
-	if (r < 0)
-		goto out;
-
 	/* expect 0xff 0xee */
 	r = ch341_get_status(dev, priv);
 	if (r < 0)
 		goto out;
 
-	r = ch341_init_set_baudrate(dev, priv, 0);
+	r = ch341_init_set_baudrate(dev, priv, 0xc3);
 	if (r < 0)
 		goto out;
 
-- 
2.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux