NetBSD-Bugs archive

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

Re: kern/49115



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.


Home | Main Index | Thread Index | Old Index