Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Followling an advice in a linux forum, don't upd...
details: https://anonhg.NetBSD.org/src/rev/f03a600d9825
branches: trunk
changeset: 349504:f03a600d9825
user: bouyer <bouyer%NetBSD.org@localhost>
date: Mon Dec 12 16:47:06 2016 +0000
description:
Followling an advice in a linux forum, don't update LCR1/LCR2.
With this change this CH340 usb/serial based device:
https://www.olimex.com/Products/Breadboarding/BB-CH340T/open-source-hardware
(the chip is written H340T)
works as expected. As I'm not sure if this is needed for older device,
make this change for sc_version 0x30 or newer only.
While there, match USB_PRODUCT_WINCHIPHEAD2_CH341_2 too.
diffstat:
sys/dev/usb/uchcom.c | 85 +++++++++++++++++++++++++++------------------------
1 files changed, 45 insertions(+), 40 deletions(-)
diffs (133 lines):
diff -r fac1378a04f6 -r f03a600d9825 sys/dev/usb/uchcom.c
--- a/sys/dev/usb/uchcom.c Mon Dec 12 16:43:14 2016 +0000
+++ b/sys/dev/usb/uchcom.c Mon Dec 12 16:47:06 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uchcom.c,v 1.16 2016/11/25 12:56:29 skrll Exp $ */
+/* $NetBSD: uchcom.c,v 1.17 2016/12/12 16:47:06 bouyer Exp $ */
/*
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uchcom.c,v 1.16 2016/11/25 12:56:29 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uchcom.c,v 1.17 2016/12/12 16:47:06 bouyer Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -95,6 +95,7 @@
#define UCHCOM_REG_LCR2 0x25
#define UCHCOM_VER_20 0x20
+#define UCHCOM_VER_30 0x30
#define UCHCOM_BASE_UNKNOWN 0
#define UCHCOM_BPS_MOD_BASE 20000000
@@ -180,6 +181,7 @@
static const struct usb_devno uchcom_devs[] = {
{ USB_VENDOR_WINCHIPHEAD, USB_PRODUCT_WINCHIPHEAD_CH341SER },
{ USB_VENDOR_WINCHIPHEAD2, USB_PRODUCT_WINCHIPHEAD2_CH341 },
+ { USB_VENDOR_WINCHIPHEAD2, USB_PRODUCT_WINCHIPHEAD2_CH341_2 },
};
#define uchcom_lookup(v, p) usb_lookup(uchcom_devs, v, p)
@@ -572,6 +574,7 @@
usbd_errstr(err));
return EIO;
}
+ DPRINTF(("%s: update_version %d\n", device_xname(sc->sc_dev), sc->sc_version));
return 0;
}
@@ -717,50 +720,52 @@
static int
set_line_control(struct uchcom_softc *sc, tcflag_t cflag)
{
- usbd_status err;
- uint8_t lcr1val = 0, lcr2val = 0;
+ if (sc->sc_version < UCHCOM_VER_30) {
+ 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;
- }
+ 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;
+ lcr1val &= ~UCHCOM_LCR1_MASK;
+ lcr2val &= ~UCHCOM_LCR2_MASK;
- /*
- * XXX: it is difficult to handle the line control appropriately:
- * - CS8, !CSTOPB and any parity mode seems ok, but
- * - the chip doesn't have the function to calculate parity
- * in !CS8 mode.
- * - it is unclear that the chip supports CS5,6 mode.
- * - it is unclear how to handle stop bits.
- */
+ /*
+ * XXX: it is difficult to handle the line control appropriately:
+ * - CS8, !CSTOPB and any parity mode seems ok, but
+ * - the chip doesn't have the function to calculate parity
+ * in !CS8 mode.
+ * - it is unclear that the chip supports CS5,6 mode.
+ * - it is unclear how to handle stop bits.
+ */
- switch (ISSET(cflag, CSIZE)) {
- case CS5:
- case CS6:
- case CS7:
- return EINVAL;
- case CS8:
- break;
- }
+ switch (ISSET(cflag, CSIZE)) {
+ case CS5:
+ case CS6:
+ case CS7:
+ return EINVAL;
+ case CS8:
+ break;
+ }
- if (ISSET(cflag, PARENB)) {
- lcr1val |= UCHCOM_LCR1_PARENB;
- if (ISSET(cflag, PARODD))
- lcr2val |= UCHCOM_LCR2_PARODD;
- else
- lcr2val |= UCHCOM_LCR2_PAREVEN;
- }
+ 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;
+ 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;
+ }
}
return 0;
Home |
Main Index |
Thread Index |
Old Index