All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: linux-usb@vger.kernel.org
Cc: Aidan Thornton <makosoft@gmail.com>,
	Grigori Goronzy <greg@chown.ath.cx>,
	Karl Palsson <karlp@tweak.net.au>,
	Russell Senior <russell@personaltelco.net>,
	Eddi De Pieri <eddi@depieri.net>, Johan Hovold <johan@kernel.org>,
	stable <stable@vger.kernel.org>
Subject: [PATCH 06/13] USB: serial: ch341: fix initial line settings
Date: Wed, 14 Dec 2016 16:28:03 +0100	[thread overview]
Message-ID: <20161214152810.14682-7-johan@kernel.org> (raw)
In-Reply-To: <20161214152810.14682-1-johan@kernel.org>

The ch341 driver is based on reverse-engineering and contains some bits
which appear to be redundant and some which appear incompatible which
certain devices.

Specifically, some CH340 devices seem unable to change the initial line
settings, which have so far been set to 5N1. Let's use a more reasonable
8N1 default instead.

Note that we also need to set the ENABLE_RX bit or receive will be
disabled after a reset during resume.

Also drop a redundant LCR-register read.

Fixes: 6ce76104781a ("USB: Driver for CH341 USB-serial adaptor")
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/ch341.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index cbe91b232828..3d86272a4b31 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -203,6 +203,7 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
 	char *buffer;
 	int r;
 	const unsigned size = 8;
+	u8 lcr;
 
 	buffer = kmalloc(size, GFP_KERNEL);
 	if (!buffer)
@@ -218,12 +219,12 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
 	if (r < 0)
 		goto out;
 
-	/* expect two bytes 0x56 0x00 */
-	r = ch341_control_in(dev, CH341_REQ_READ_REG, 0x2518, 0, buffer, size);
-	if (r < 0)
-		goto out;
-
-	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, 0x0050);
+	/*
+	 * Some CH340 devices appear unable to change the initial LCR
+	 * settings, so set a sane 8N1 default.
+	 */
+	lcr = CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX | CH341_LCR_CS8;
+	r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, lcr);
 	if (r < 0)
 		goto out;
 
@@ -232,7 +233,7 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
 	if (r < 0)
 		goto out;
 
-	r = ch341_init_set_baudrate(dev, priv, 0);
+	r = ch341_init_set_baudrate(dev, priv, lcr);
 	if (r < 0)
 		goto out;
 
-- 
2.10.2


  parent reply	other threads:[~2016-12-14 15:28 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20161214152810.14682-1-johan@kernel.org>
2016-12-14 15:27 ` [PATCH 01/13] USB: serial: ch341: fix initial modem-control state Johan Hovold
2016-12-14 15:27 ` [PATCH 02/13] USB: serial: ch341: fix open and resume after B0 Johan Hovold
2016-12-14 15:28 ` [PATCH 03/13] USB: serial: ch341: fix modem-control and B0 handling Johan Hovold
2016-12-14 15:28 ` [PATCH 04/13] USB: serial: ch341: fix open error handling Johan Hovold
2016-12-14 15:28 ` [PATCH 05/13] USB: serial: ch341: fix resume after reset Johan Hovold
2016-12-14 15:28 ` Johan Hovold [this message]
2016-12-16 13:19   ` [PATCH 06/13] USB: serial: ch341: fix initial line settings Aidan Thornton
2016-12-16 14:46     ` Johan Hovold
2016-12-16 16:04       ` Russell Senior
2016-12-16 16:13         ` Johan Hovold
2016-12-16 17:30           ` Johan Hovold
2016-12-17 11:27             ` Russell Senior
2016-12-19 10:58               ` Johan Hovold
2016-12-19 16:40                 ` Russell Senior
2016-12-19 22:12                   ` Russell Senior
2016-12-20  9:13                     ` Johan Hovold
2016-12-20 12:38                       ` Russell Senior
2016-12-20 16:07                         ` Johan Hovold
2016-12-20 16:13                           ` Johan Hovold
2016-12-20 20:09                           ` Russell Senior
2016-12-20 20:49                             ` Johan Hovold
2017-01-09 13:51                               ` Johan Hovold
2017-01-12 14:49                                 ` Johan Hovold
2016-12-20 15:31                       ` Russell Senior
2016-12-20 15:52                         ` Johan Hovold
2016-12-20 20:05                           ` Russell Senior
2016-12-20  8:42                   ` 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=20161214152810.14682-7-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=eddi@depieri.net \
    --cc=greg@chown.ath.cx \
    --cc=karlp@tweak.net.au \
    --cc=linux-usb@vger.kernel.org \
    --cc=makosoft@gmail.com \
    --cc=russell@personaltelco.net \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.