NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: kern/49115
The following reply was made to PR kern/49115; it has been noted by GNATS.
From: Vicente Chaves de Melo <vicente.melo.br%ieee.org@localhost>
To: Kamil Rytarowski <n54%gmx.com@localhost>, gnats-bugs%netbsd.org@localhost,
gnats-admin%netbsd.org@localhost, netbsd-bugs%netbsd.org@localhost
Cc:
Subject: Re: kern/49115
Date: Wed, 10 Jun 2015 23:48:24 -0300
This is a multi-part message in MIME format.
--------------090103040904040800000404
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Hello Kamil
I created the following patch to NetBSD7
based OpenBSD
http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/usb/uchcom.c
Revision 1.20 that contains the following description
"It seems that there is new and old revision of CH340.
Previous uchcom(4) driver targeted old one, and new one could not work
because of uchcom_set_line_control() broke the value of
UCHCOM_REG_LCR1(0x18).
To support new CH340, uchcom_set_line_control() and uchcom_reset_chip()
have been overhauled. Current uchcom(4) does not change the value of
UCHCOM_REG_LCR1 register, it means even/odd parity mode is no longer
supported with old CH340."
dm4# cvs diff sys/dev/usb/
cvs diff: Diffing .
cvs diff: Diffing sys
cvs diff: Diffing sys/dev
cvs diff: Diffing sys/dev/usb
Index: sys/dev/usb/uchcom.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/uchcom.c,v
retrieving revision 1.13
diff -r1.13 uchcom.c
105,111d104
< #define UCHCOM_LCR1_MASK 0xAF
< #define UCHCOM_LCR2_MASK 0x07
< #define UCHCOM_LCR1_PARENB 0x80
< #define UCHCOM_LCR2_PAREVEN 0x07
< #define UCHCOM_LCR2_PARODD 0x06
< #define UCHCOM_LCR2_PARMARK 0x05
< #define UCHCOM_LCR2_PARSPACE 0x04
116a110,116
> /*
> * XXX - these magic numbers come from Linux (drivers/usb/serial/ch341.c).
> * The manufacturer was unresponsive when asked for documentation.
> */
> #define UCHCOM_RESET_VALUE 0x501F /* line mode? */
> #define UCHCOM_RESET_INDEX 0xD90A /* baud rate? */
>
718,730d717
< usbd_status err;
< uint8_t lcr1val = 0, lcr2val = 0;
<
< err = read_reg(sc, UCHCOM_REG_LCR1, &lcr1val, UCHCOM_REG_LCR2,
&lcr2val);
< if (err) {
< aprint_error_dev(sc->sc_dev, "cannot get LCR: %s\n",
< usbd_errstr(err));
< return EIO;
< }
<
< lcr1val &= ~UCHCOM_LCR1_MASK;
< lcr2val &= ~UCHCOM_LCR2_MASK;
<
749,762c736,737
< if (ISSET(cflag, PARENB)) {
< lcr1val |= UCHCOM_LCR1_PARENB;
< if (ISSET(cflag, PARODD))
< lcr2val |= UCHCOM_LCR2_PARODD;
< else
< lcr2val |= UCHCOM_LCR2_PAREVEN;
< }
<
< err = write_reg(sc, UCHCOM_REG_LCR1, lcr1val, UCHCOM_REG_LCR2,
lcr2val);
< if (err) {
< aprint_error_dev(sc->sc_dev, "cannot set LCR: %s\n",
< usbd_errstr(err));
< return EIO;
< }
---
> if (ISSET(cflag, PARENB) || ISSET(cflag, CSTOPB))
> return EINVAL;
787,811d761
< uint8_t lcr1val, lcr2val, pre, div, mod;
< uint16_t val=0, idx=0;
<
< err = read_reg(sc, UCHCOM_REG_LCR1, &lcr1val, UCHCOM_REG_LCR2,
&lcr2val);
< if (err)
< goto failed;
<
< err = read_reg(sc, UCHCOM_REG_BPS_PRE, &pre, UCHCOM_REG_BPS_DIV,
&div);
< if (err)
< goto failed;
<
< err = read_reg(sc, UCHCOM_REG_BPS_MOD, &mod, UCHCOM_REG_BPS_PAD,
NULL);
< if (err)
< goto failed;
<
< val |= (uint16_t)(lcr1val&0xF0) << 8;
< val |= 0x01;
< val |= (uint16_t)(lcr2val&0x0F) << 8;
< val |= 0x02;
< idx |= pre & 0x07;
< val |= 0x04;
< idx |= (uint16_t)div << 8;
< val |= 0x08;
< idx |= mod & 0xF8;
< val |= 0x10;
816c766,769
< err = generic_control_out(sc, UCHCOM_REQ_RESET, val, idx);
---
> err = generic_control_out(sc, UCHCOM_REQ_RESET,
> UCHCOM_RESET_VALUE,
> UCHCOM_RESET_INDEX);
>
and now the USB-Serial converter works as we can see below:
dm4# *tip ttyU0-9600*
connected
NetBSD/amd64 (netbsd7.XXXXXXX.net) (console)
login: root
Password:
Jun 10 23:31:43 netbsd7 login: ROOT LOGIN (root) on tty console
Last login: Wed Jun 10 23:11:17 2015 on console
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014
The NetBSD Foundation, Inc. All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
The Regents of the University of California. All rights reserved.
NetBSD 7.0_BETA (GENERIC) #0: Wed May 13 01:37:49 BRT 2015
You have new mail.
Terminal type is vt100.
We recommend that you create a non-root account and use su(1) for root
access.
netbsd7# ~
[EOT]
with the following line in the file /etc/remote:
ttyU0-9600:dv=/dev/ttyU0:br#9600:pa=none:dc:
It would be nice if someone more experienced than I can review the patch
Vicente.
On 10/06/2015 19:35, Kamil Rytarowski wrote:
> On 10.06.2015 18:49, Vicente Chaves de Melo wrote:
>> Hi Kamil,
>> sorry to intrude but you managed to solve this problem?
>> I believe I have exactly the same USB-Serial converter described in this
>> PR.
>> And I couldn't make it work with NetBSD7 + tip, although run smoothly
>> with OpenBSD 5.7 + tip, Linux + minicom and even with Windows + putty .
>> In advance, thank you very much for your attention.
> I ran out of time to test it on others than NetBSD platforms. I had
> problems with Linux as well and switched to other serial.
>
> If you like you can take this problem and backport OpenBSD enhancements
> and I will test them.
>
> When I will get a free metal to install there OpenBSD I will test it there.
> .
>
--------------090103040904040800000404
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello Kamil<br>
I created the following patch to NetBSD7<br>
based OpenBSD
<a class="moz-txt-link-freetext" href="http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/usb/uchcom.c">http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/sys/dev/usb/uchcom.c</a>
Revision 1.20 that contains the following description<br>
<br>
"It seems that there is new and old revision of CH340.<br>
Previous uchcom(4) driver targeted old one, and new one could not
work<br>
because of uchcom_set_line_control() broke the value of<br>
UCHCOM_REG_LCR1(0x18).<br>
<br>
To support new CH340, uchcom_set_line_control() and
uchcom_reset_chip()<br>
have been overhauled. Current uchcom(4) does not change the value of<br>
UCHCOM_REG_LCR1 register, it means even/odd parity mode is no longer<br>
supported with old CH340."<br>
<br>
<tt>dm4# cvs diff sys/dev/usb/</tt><tt><br>
</tt><tt>cvs diff: Diffing .</tt><tt><br>
</tt><tt>cvs diff: Diffing sys</tt><tt><br>
</tt><tt>cvs diff: Diffing sys/dev</tt><tt><br>
</tt><tt>cvs diff: Diffing sys/dev/usb</tt><tt><br>
</tt><tt>Index: sys/dev/usb/uchcom.c</tt><tt><br>
</tt><tt>===================================================================</tt><tt><br>
</tt><tt>RCS file: /cvsroot/src/sys/dev/usb/uchcom.c,v</tt><tt><br>
</tt><tt>retrieving revision 1.13</tt><tt><br>
</tt><tt>diff -r1.13 uchcom.c</tt><tt><br>
</tt><tt>105,111d104</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR1_MASK 0xAF</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR2_MASK 0x07</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR1_PARENB 0x80</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR2_PAREVEN 0x07</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR2_PARODD 0x06</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR2_PARMARK 0x05</tt><tt><br>
</tt><tt>< #define UCHCOM_LCR2_PARSPACE 0x04</tt><tt><br>
</tt><tt>116a110,116</tt><tt><br>
</tt><tt>> /*</tt><tt><br>
</tt><tt>> * XXX - these magic numbers come from Linux
(drivers/usb/serial/ch341.c).</tt><tt><br>
</tt><tt>> * The manufacturer was unresponsive when asked for
documentation.</tt><tt><br>
</tt><tt>> */</tt><tt><br>
</tt><tt>> #define UCHCOM_RESET_VALUE 0x501F /* line mode?
*/</tt><tt><br>
</tt><tt>> #define UCHCOM_RESET_INDEX 0xD90A /* baud rate?
*/</tt><tt><br>
</tt><tt>></tt><tt><br>
</tt><tt>718,730d717</tt><tt><br>
</tt><tt>< usbd_status err;</tt><tt><br>
</tt><tt>< uint8_t lcr1val = 0, lcr2val = 0;</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< err = read_reg(sc, UCHCOM_REG_LCR1,
&lcr1val, UCHCOM_REG_LCR2, &lcr2val);</tt><tt><br>
</tt><tt>< if (err) {</tt><tt><br>
</tt><tt>< aprint_error_dev(sc->sc_dev, "cannot
get LCR: %s\n",</tt><tt><br>
</tt><tt>< usbd_errstr(err));</tt><tt><br>
</tt><tt>< return EIO;</tt><tt><br>
</tt><tt>< }</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< lcr1val &= ~UCHCOM_LCR1_MASK;</tt><tt><br>
</tt><tt>< lcr2val &= ~UCHCOM_LCR2_MASK;</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>749,762c736,737</tt><tt><br>
</tt><tt>< if (ISSET(cflag, PARENB)) {</tt><tt><br>
</tt><tt>< lcr1val |= UCHCOM_LCR1_PARENB;</tt><tt><br>
</tt><tt>< if (ISSET(cflag, PARODD))</tt><tt><br>
</tt><tt>< lcr2val |= UCHCOM_LCR2_PARODD;</tt><tt><br>
</tt><tt>< else</tt><tt><br>
</tt><tt>< lcr2val |= UCHCOM_LCR2_PAREVEN;</tt><tt><br>
</tt><tt>< }</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< err = write_reg(sc, UCHCOM_REG_LCR1, lcr1val,
UCHCOM_REG_LCR2, lcr2val);</tt><tt><br>
</tt><tt>< if (err) {</tt><tt><br>
</tt><tt>< aprint_error_dev(sc->sc_dev, "cannot
set LCR: %s\n",</tt><tt><br>
</tt><tt>< usbd_errstr(err));</tt><tt><br>
</tt><tt>< return EIO;</tt><tt><br>
</tt><tt>< }</tt><tt><br>
</tt><tt>---</tt><tt><br>
</tt><tt>> if (ISSET(cflag, PARENB) || ISSET(cflag,
CSTOPB))</tt><tt><br>
</tt><tt>> return EINVAL;</tt><tt><br>
</tt><tt>787,811d761</tt><tt><br>
</tt><tt>< uint8_t lcr1val, lcr2val, pre, div, mod;</tt><tt><br>
</tt><tt>< uint16_t val=0, idx=0;</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< err = read_reg(sc, UCHCOM_REG_LCR1,
&lcr1val, UCHCOM_REG_LCR2, &lcr2val);</tt><tt><br>
</tt><tt>< if (err)</tt><tt><br>
</tt><tt>< goto failed;</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< err = read_reg(sc, UCHCOM_REG_BPS_PRE, &pre,
UCHCOM_REG_BPS_DIV, &div);</tt><tt><br>
</tt><tt>< if (err)</tt><tt><br>
</tt><tt>< goto failed;</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< err = read_reg(sc, UCHCOM_REG_BPS_MOD, &mod,
UCHCOM_REG_BPS_PAD, NULL);</tt><tt><br>
</tt><tt>< if (err)</tt><tt><br>
</tt><tt>< goto failed;</tt><tt><br>
</tt><tt><</tt><tt><br>
</tt><tt>< val |= (uint16_t)(lcr1val&0xF0) << 8;</tt><tt><br>
</tt><tt>< val |= 0x01;</tt><tt><br>
</tt><tt>< val |= (uint16_t)(lcr2val&0x0F) << 8;</tt><tt><br>
</tt><tt>< val |= 0x02;</tt><tt><br>
</tt><tt>< idx |= pre & 0x07;</tt><tt><br>
</tt><tt>< val |= 0x04;</tt><tt><br>
</tt><tt>< idx |= (uint16_t)div << 8;</tt><tt><br>
</tt><tt>< val |= 0x08;</tt><tt><br>
</tt><tt>< idx |= mod & 0xF8;</tt><tt><br>
</tt><tt>< val |= 0x10;</tt><tt><br>
</tt><tt>816c766,769</tt><tt><br>
</tt><tt>< err = generic_control_out(sc, UCHCOM_REQ_RESET,
val, idx);</tt><tt><br>
</tt><tt>---</tt><tt><br>
</tt><tt>> err = generic_control_out(sc, UCHCOM_REQ_RESET,</tt><tt><br>
</tt><tt>> UCHCOM_RESET_VALUE,</tt><tt><br>
</tt><tt>> UCHCOM_RESET_INDEX);</tt><tt><br>
</tt><tt>></tt><br>
<br>
and now the USB-Serial converter works as we can see below:<br>
<br>
<tt>dm4# <b>tip ttyU0-9600</b></tt><tt><br>
</tt><tt>connected</tt><tt><br>
</tt><tt><br>
</tt><tt><br>
</tt><tt>NetBSD/amd64 (netbsd7.XXXXXXX.net) (console)</tt><tt><br>
</tt><tt><br>
</tt><tt>login: root</tt><tt><br>
</tt><tt>Password:</tt><tt><br>
</tt><tt>Jun 10 23:31:43 netbsd7 login: ROOT LOGIN (root) on tty
console</tt><tt><br>
</tt><tt>Last login: Wed Jun 10 23:11:17 2015 on console</tt><tt><br>
</tt><tt>Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2003, 2004, 2005,</tt><tt><br>
</tt><tt> 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014</tt><tt><br>
</tt><tt> The NetBSD Foundation, Inc. All rights reserved.</tt><tt><br>
</tt><tt>Copyright (c) 1982, 1986, 1989, 1991, 1993</tt><tt><br>
</tt><tt> The Regents of the University of California. All
rights reserved.</tt><tt><br>
</tt><tt><br>
</tt><tt>NetBSD 7.0_BETA (GENERIC) #0: Wed May 13 01:37:49 BRT 2015</tt><tt><br>
</tt><tt><br>
</tt><tt>You have new mail.</tt><tt><br>
</tt><tt>Terminal type is vt100.</tt><tt><br>
</tt><tt>We recommend that you create a non-root account and use
su(1) for root access.</tt><tt><br>
</tt><tt>netbsd7# ~</tt><tt><br>
</tt><tt>[EOT]</tt><br>
<br>
with the following line in the file /etc/remote:<br>
<tt>ttyU0-9600:dv=/dev/ttyU0:br#9600:pa=none:dc:</tt><br>
<br>
It would be nice if someone more experienced than I can review the
patch<br>
<br>
Vicente.<br>
<br>
<div class="moz-cite-prefix">On 10/06/2015 19:35, Kamil Rytarowski
wrote:<br>
</div>
<blockquote cite="mid:5578BBCF.3040704%gmx.com@localhost" type="cite">
<pre wrap="">On 10.06.2015 18:49, Vicente Chaves de Melo wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Hi Kamil,
sorry to intrude but you managed to solve this problem?
I believe I have exactly the same USB-Serial converter described in this
PR.
And I couldn't make it work with NetBSD7 + tip, although run smoothly
with OpenBSD 5.7 + tip, Linux + minicom and even with Windows + putty .
In advance, thank you very much for your attention.
</pre>
</blockquote>
<pre wrap="">
I ran out of time to test it on others than NetBSD platforms. I had
problems with Linux as well and switched to other serial.
If you like you can take this problem and backport OpenBSD enhancements
and I will test them.
When I will get a free metal to install there OpenBSD I will test it there.
.
</pre>
</blockquote>
<br>
</body>
</html>
--------------090103040904040800000404--
Home |
Main Index |
Thread Index |
Old Index