From patchwork Wed Feb 13 12:30:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Yeh X-Patchwork-Id: 10809687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3492513BF for ; Wed, 13 Feb 2019 12:30:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1531C2CEF5 for ; Wed, 13 Feb 2019 12:30:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0984D2CEED; Wed, 13 Feb 2019 12:30:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D2862CEBE for ; Wed, 13 Feb 2019 12:30:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404086AbfBMMaY (ORCPT ); Wed, 13 Feb 2019 07:30:24 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:46592 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404084AbfBMMaX (ORCPT ); Wed, 13 Feb 2019 07:30:23 -0500 Received: by mail-pf1-f196.google.com with SMTP id g6so1061170pfh.13 for ; Wed, 13 Feb 2019 04:30:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8kjFeBCDKO/tuZmXZjy+qBBAv5TlMNd2DIVZHV0owyU=; b=SpG+4jnh84m/+sHoIiqHLYObxLK2SVtt2MPIwqDwbN5xiUBv0HDaLAVD4ohsutTSw9 +IwK7Ldgrjy7Ep2hE8aS5TC/GEwcAnKx4R3fRhxxFJ26uT5gyKA5upzcZM4MUtzwFVM1 84fOdMxr68YkKilQ6kHJh00zd18IAWdeIFXHhLgF5OXuldACEUAyr9RZZEhTeOKLErqM Yk7MwuSUgB8RqfL37okW9ypGIoEHivQPpg28aqeXpdrYsE+AHH+qtosCStAF/N7xzrpc o9UKJ6q99BT9fLIDJoPH43SwbCu7dkmIokUEmSwwEHnYoge3QEGDByVRiN2yGUvuFdNh zOdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8kjFeBCDKO/tuZmXZjy+qBBAv5TlMNd2DIVZHV0owyU=; b=RDjXXIAn7WmhGEQWheNHsPa6+v+CBipwUDXdDgFmqRr+spTOWNYOwQv6+YVx0mv5Kf 6XiulG961QcWnk9jVCGE1m6HDwvNtoS0XfWw3291UpWOh2Nkss2FAf+hD4FCaneahSWZ Uj6ytfnHJfTbqbILc8ZRJYvP9K/w2HsplI/9xk+gRv+KNrc/kaxLaaHusK7r6qQ9as4C uX6h0XnqpeN/Pa8dHARcEhwTRg+CoJP6J4HRAuHSyKzYaP+5k5yYQkQ2TsZA15MU4Dpy H4O9LWovpqwPzK1GNpRiolph/nmj5jVdj4Yo4GbB8TVQV+wCQgx15JTNWx7tR7DtU33u UMhA== X-Gm-Message-State: AHQUAubZX6RKcxNQTTG9RGVS91a2Q18dCtAVeXsrTcFTMYM48UCqvbEM /SshFKFVZk1LFIJCBEyxUHA= X-Google-Smtp-Source: AHgI3IZgjipmfEuoPI1UA9fbzzQb2r7jA1jghqamate6VBU75Ff0vqEUF17iVzogRHghe0RBnBak6A== X-Received: by 2002:a63:5153:: with SMTP id r19mr227956pgl.281.1550061022439; Wed, 13 Feb 2019 04:30:22 -0800 (PST) Received: from localhost.localdomain (111-249-11-166.dynamic-ip.hinet.net. [111.249.11.166]) by smtp.gmail.com with ESMTPSA id b9sm17524823pgt.66.2019.02.13.04.30.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 04:30:21 -0800 (PST) From: Charles Yeh To: gregkh@linuxfoundation.org, johan@kernel.org, linux-usb@vger.kernel.org Cc: charles-yeh@prolific.com.tw, Charles Yeh Subject: [PATCH] USB:serial:pl2303:Add new PID to support PL2303HXN (TYPE_HXN) Date: Wed, 13 Feb 2019 20:30:00 +0800 Message-Id: <20190213123000.4656-1-charlesyeh522@gmail.com> X-Mailer: git-send-email 2.20.1.windows.1 MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prolific has developed a new USB to UART chip: PL2303HXN (PL2303GC/PL2303GS/PL2303GT/PL2303GL/PL2303GE) The Vendor request used by the PL2303HXN (TYPE_HXN) is different from the existing PL2303 series (TYPE_HX & TYPE_01). Therefore, different Vendor requests are used to issue related commands. 1. Added a new TYPE_HXN type in pl2303_type_data, and then executes new Vendor request, new flow control and other related instructions if TYPE_HXN is recognized. 2. Because the new PL2303HXN can only accept the new Vendor request, the old Vendor request cannot be accepted (the error message will be returned) So first determine the TYPE_HX or TYPE_HXN through TYPE_HX_READ_STATUS_REG in pl2303_startup. 2.1 If the return message is "1", then the PL2303 is the existing TYPE_HX/ TYPE_01 series. The other settings in pl2303_startup are to continue execution. 2.2 If the return message is "not 1", then the PL2303 is the new TYPE_HXN series. The other settings in pl2303_startup are ignored. (PL2303HXN will directly use the default value in the hardware, no need to add additional settings through the software) 3. In pl2303_open: Because TYPE_HXN is different from the instruction of down/up stream used by TYPE_HX. Therefore, we will also execute different instructions here. 4. In pl2303_set_termios: The UART flow control instructions used by TYPE_HXN/TYPE_HX/TYPE_01 are different. Therefore, we will also execute different instructions here. 5. In pl2303_vendor_read & pl2303_vendor_write, since TYPE_HXN is different from the vendor request instruction used by TYPE_HX/TYPE_01, it will also execute different instructions here. Signed-off-by: Charles Yeh --- drivers/usb/serial/pl2303.c | 131 +++++++++++++++++++++++++++++------- drivers/usb/serial/pl2303.h | 7 ++ 2 files changed, 113 insertions(+), 25 deletions(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index bb3f9aa4a909..d7d557e01390 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -47,6 +47,12 @@ static const struct usb_device_id id_table[] = { { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MOTOROLA) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ZTEK) }, { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_TB) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GC) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GB) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GT) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GL) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GE) }, + { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GS) }, { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) }, { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) }, { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID), @@ -129,9 +135,11 @@ MODULE_DEVICE_TABLE(usb, id_table); #define VENDOR_WRITE_REQUEST_TYPE 0x40 #define VENDOR_WRITE_REQUEST 0x01 +#define VENDOR_WRITE_NREQUEST 0x80 #define VENDOR_READ_REQUEST_TYPE 0xc0 #define VENDOR_READ_REQUEST 0x01 +#define VENDOR_READ_NREQUEST 0x81 #define UART_STATE_INDEX 8 #define UART_STATE_MSR_MASK 0x8b @@ -145,11 +153,30 @@ MODULE_DEVICE_TABLE(usb, id_table); #define UART_OVERRUN_ERROR 0x40 #define UART_CTS 0x80 +#define TYPE_HX_READ_STATUS_REG 0x8080 +#define TYPE_HXN_FLOWCONTROL_REG 0x0A +#define TYPE_HXN_HARDWAREFLOW_DATA 0xFA +#define TYPE_HXN_SOFTWAREFLOW_DATA 0xEE +#define TYPE_HXN_NOFLOW_DATA 0xFF +#define TYPE_HX_01_FLOWCONTROL_REG 0x00 +#define TYPE_01_HARDWAREFLOW_DATA 0x41 +#define TYPE_HX_HARDWAREFLOW_DATA 0x61 +#define TYPE_HX_01_SOFTWAREFLOW_DATA 0xC0 +#define TYPE_HX_01_NOFLOW_DATA 0x00 +#define UART_XON_CHAR 0x11 +#define UART_XOFF_CHAR 0x13 +#define HX_RESET_DOWN_UPSTREAM_REG1 0x08 +#define HX_RESET_DOWN_UPSTREAM_REG2 0x09 +#define HX_RESET_DOWN_UPSTREAM_DATA 0x00 +#define HXN_RESET_DOWN_UPSTREAM_REG 0x07 +#define HXN_RESET_DOWN_UPSTREAM_DATA 0x00 + static void pl2303_set_break(struct usb_serial_port *port, bool enable); enum pl2303_type { TYPE_01, /* Type 0 and 1 (difference unknown) */ TYPE_HX, /* HX version of the pl2303 chip */ + TYPE_HXN, /* HXN version of the pl2303 chip */ TYPE_COUNT }; @@ -179,16 +206,26 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { [TYPE_HX] = { .max_baud_rate = 12000000, }, + [TYPE_HXN] = { + .max_baud_rate = 12000000, + }, }; static int pl2303_vendor_read(struct usb_serial *serial, u16 value, unsigned char buf[1]) { struct device *dev = &serial->interface->dev; + struct pl2303_serial_private *spriv = usb_get_serial_data(serial); int res; + u8 request; + + if (spriv->type == &pl2303_type_data[TYPE_HXN]) + request = VENDOR_READ_NREQUEST; + else + request = VENDOR_READ_REQUEST; res = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, + request, VENDOR_READ_REQUEST_TYPE, value, 0, buf, 1, 100); if (res != 1) { dev_err(dev, "%s - failed to read [%04x]: %d\n", __func__, @@ -207,12 +244,19 @@ static int pl2303_vendor_read(struct usb_serial *serial, u16 value, static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index) { struct device *dev = &serial->interface->dev; + struct pl2303_serial_private *spriv = usb_get_serial_data(serial); int res; + u8 request; dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index); + if (spriv->type == &pl2303_type_data[TYPE_HXN]) + request = VENDOR_WRITE_NREQUEST; + else + request = VENDOR_WRITE_REQUEST; + res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE, + request, VENDOR_WRITE_REQUEST_TYPE, value, index, NULL, 0, 100); if (res) { dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__, @@ -292,6 +336,7 @@ static int pl2303_startup(struct usb_serial *serial) struct pl2303_serial_private *spriv; enum pl2303_type type = TYPE_01; unsigned char *buf; + int res; spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); if (!spriv) @@ -313,26 +358,37 @@ static int pl2303_startup(struct usb_serial *serial) type = TYPE_01; /* type 1 */ dev_dbg(&serial->interface->dev, "device type: %d\n", type); + if (type == TYPE_HX) { + res = usb_control_msg(serial->dev, + usb_rcvctrlpipe(serial->dev, 0), + VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, + TYPE_HX_READ_STATUS_REG, 0, buf, 1, 100); + if (res != 1) + type = TYPE_HXN; + } + spriv->type = &pl2303_type_data[type]; spriv->quirks = (unsigned long)usb_get_serial_data(serial); spriv->quirks |= spriv->type->quirks; usb_set_serial_data(serial, spriv); - pl2303_vendor_read(serial, 0x8484, buf); - pl2303_vendor_write(serial, 0x0404, 0); - pl2303_vendor_read(serial, 0x8484, buf); - pl2303_vendor_read(serial, 0x8383, buf); - pl2303_vendor_read(serial, 0x8484, buf); - pl2303_vendor_write(serial, 0x0404, 1); - pl2303_vendor_read(serial, 0x8484, buf); - pl2303_vendor_read(serial, 0x8383, buf); - pl2303_vendor_write(serial, 0, 1); - pl2303_vendor_write(serial, 1, 0); - if (spriv->quirks & PL2303_QUIRK_LEGACY) - pl2303_vendor_write(serial, 2, 0x24); - else - pl2303_vendor_write(serial, 2, 0x44); + if (type != TYPE_HXN) { + pl2303_vendor_read(serial, 0x8484, buf); + pl2303_vendor_write(serial, 0x0404, 0); + pl2303_vendor_read(serial, 0x8484, buf); + pl2303_vendor_read(serial, 0x8383, buf); + pl2303_vendor_read(serial, 0x8484, buf); + pl2303_vendor_write(serial, 0x0404, 1); + pl2303_vendor_read(serial, 0x8484, buf); + pl2303_vendor_read(serial, 0x8383, buf); + pl2303_vendor_write(serial, 0, 1); + pl2303_vendor_write(serial, 1, 0); + if (spriv->quirks & PL2303_QUIRK_LEGACY) + pl2303_vendor_write(serial, 2, 0x24); + else + pl2303_vendor_write(serial, 2, 0x44); + } kfree(buf); @@ -677,15 +733,30 @@ static void pl2303_set_termios(struct tty_struct *tty, } if (C_CRTSCTS(tty)) { - if (spriv->quirks & PL2303_QUIRK_LEGACY) - pl2303_vendor_write(serial, 0x0, 0x41); + if (spriv->type == &pl2303_type_data[TYPE_01]) + pl2303_vendor_write(serial, TYPE_HX_01_FLOWCONTROL_REG, + TYPE_01_HARDWAREFLOW_DATA); + else if (spriv->type == &pl2303_type_data[TYPE_HXN]) + pl2303_vendor_write(serial, TYPE_HXN_FLOWCONTROL_REG, + TYPE_HXN_HARDWAREFLOW_DATA); + else + pl2303_vendor_write(serial, TYPE_HX_01_FLOWCONTROL_REG, + TYPE_HX_HARDWAREFLOW_DATA); + } else if (I_IXON(tty) && !I_IXANY(tty) && START_CHAR(tty) == + UART_XON_CHAR && STOP_CHAR(tty) == UART_XOFF_CHAR) { + if (spriv->type == &pl2303_type_data[TYPE_HXN]) + pl2303_vendor_write(serial, TYPE_HXN_FLOWCONTROL_REG, + TYPE_HXN_SOFTWAREFLOW_DATA); else - pl2303_vendor_write(serial, 0x0, 0x61); - } else if (I_IXON(tty) && !I_IXANY(tty) && START_CHAR(tty) == 0x11 && - STOP_CHAR(tty) == 0x13) { - pl2303_vendor_write(serial, 0x0, 0xc0); + pl2303_vendor_write(serial, TYPE_HX_01_FLOWCONTROL_REG, + TYPE_HX_01_SOFTWAREFLOW_DATA); } else { - pl2303_vendor_write(serial, 0x0, 0x0); + if (spriv->type == &pl2303_type_data[TYPE_HXN]) + pl2303_vendor_write(serial, TYPE_HXN_FLOWCONTROL_REG, + TYPE_HXN_NOFLOW_DATA); + else + pl2303_vendor_write(serial, TYPE_HX_01_FLOWCONTROL_REG, + TYPE_HX_01_NOFLOW_DATA); } kfree(buf); @@ -726,8 +797,18 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port) usb_clear_halt(serial->dev, port->read_urb->pipe); } else { /* reset upstream data pipes */ - pl2303_vendor_write(serial, 8, 0); - pl2303_vendor_write(serial, 9, 0); + if (spriv->type == &pl2303_type_data[TYPE_HXN]) + pl2303_vendor_write(serial, + HXN_RESET_DOWN_UPSTREAM_REG, + HXN_RESET_DOWN_UPSTREAM_DATA); + else { + pl2303_vendor_write(serial, + HX_RESET_DOWN_UPSTREAM_REG1, + HX_RESET_DOWN_UPSTREAM_DATA); + pl2303_vendor_write(serial, + HX_RESET_DOWN_UPSTREAM_REG2, + HX_RESET_DOWN_UPSTREAM_DATA); + } } /* Setup termios */ diff --git a/drivers/usb/serial/pl2303.h b/drivers/usb/serial/pl2303.h index 559941ca884d..898ddc1a7302 100644 --- a/drivers/usb/serial/pl2303.h +++ b/drivers/usb/serial/pl2303.h @@ -21,6 +21,13 @@ #define PL2303_PRODUCT_ID_MOTOROLA 0x0307 #define PL2303_PRODUCT_ID_ZTEK 0xe1f1 +/* PL2303HXN , TYPE_HXN */ +#define PL2303G_PRODUCT_ID_GC 0x23A3 +#define PL2303G_PRODUCT_ID_GB 0x23B3 +#define PL2303G_PRODUCT_ID_GT 0x23C3 +#define PL2303G_PRODUCT_ID_GL 0x23D3 +#define PL2303G_PRODUCT_ID_GE 0x23E3 +#define PL2303G_PRODUCT_ID_GS 0x23F3 #define ATEN_VENDOR_ID 0x0557 #define ATEN_VENDOR_ID2 0x0547