From patchwork Wed Sep 16 01:56:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mychaela N. Falconia" X-Patchwork-Id: 11778677 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E222992C for ; Wed, 16 Sep 2020 02:06:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8B692087D for ; Wed, 16 Sep 2020 02:06:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726142AbgIPCG1 (ORCPT ); Tue, 15 Sep 2020 22:06:27 -0400 Received: from freecalypso.org ([195.154.163.71]:32904 "EHLO freecalypso.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgIPCGY (ORCPT ); Tue, 15 Sep 2020 22:06:24 -0400 X-Greylist: delayed 585 seconds by postgrey-1.27 at vger.kernel.org; Tue, 15 Sep 2020 22:06:24 EDT Received: by freecalypso.org (Postfix, from userid 1001) id DD21A3740240; Wed, 16 Sep 2020 01:56:29 +0000 (UTC) From: "Mychaela N. Falconia" To: Johan Hovold Cc: linux-usb@vger.kernel.org, mychaela.falconia@gmail.com Subject: [PATCH 1/3] USB: serial: ftdi_sio: add support for FreeCalypso JTAG+UART adapters Message-Id: <20200916015629.DD21A3740240@freecalypso.org> Date: Wed, 16 Sep 2020 01:56:29 +0000 (UTC) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There exist many FT2232-based JTAG+UART adapter designs in which FT2232 Channel A is used for JTAG and Channel B is used for UART. The best way to handle them in Linux is to have the ftdi_sio driver create a ttyUSB device only for Channel B and not for Channel A: a ttyUSB device for Channel A would be bogus and will disappear as soon as the user runs OpenOCD or other applications that access Channel A for JTAG from userspace, causing undesirable noise for users. The ftdi_sio driver already has a dedicated quirk for such JTAG+UART FT2232 adapters, and it requires assigning custom USB IDs to such adapters and adding these IDs to the driver with the ftdi_jtag_quirk applied. Boutique hardware manufacturer Falconia Partners LLC has created a couple of JTAG+UART adapter designs (one buffered, one unbuffered) as part of FreeCalypso project, and this hardware is specifically made to be used with Linux hosts, with the intent that Channel A will be accessed only from userspace via appropriate applications, and that Channel B will be supported by the ftdi_sio kernel driver, presenting a standard ttyUSB device to userspace. Toward this end the hardware manufacturer will be programming FT2232 EEPROMs with custom USB IDs, specifically with the intent that these IDs will be recognized by the ftdi_sio driver with the ftdi_jtag_quirk applied. Signed-off-by: Mychaela N. Falconia --- drivers/usb/serial/ftdi_sio.c | 5 +++++ drivers/usb/serial/ftdi_sio_ids.h | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 9823bb424abd..8d89a1650dad 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -1037,6 +1037,11 @@ static const struct usb_device_id id_table_combined[] = { /* U-Blox devices */ { USB_DEVICE(UBLOX_VID, UBLOX_C099F9P_ZED_PID) }, { USB_DEVICE(UBLOX_VID, UBLOX_C099F9P_ODIN_PID) }, + /* FreeCalypso USB adapters */ + { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_JTAG_BUF_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_JTAG_UNBUF_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, { } /* Terminating entry */ }; diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h index b5ca17a5967a..5b2405ac9ae0 100644 --- a/drivers/usb/serial/ftdi_sio_ids.h +++ b/drivers/usb/serial/ftdi_sio_ids.h @@ -589,6 +589,14 @@ #define FTDI_CUSTOMWARE_MINIPLEX2WI_PID 0xfd4a /* MiniPlex-2Wi */ #define FTDI_CUSTOMWARE_MINIPLEX3_PID 0xfd4b /* MiniPlex-3 series */ +/* + * Custom USB adapters made by Falconia Partners LLC + * for FreeCalypso project, ID codes allocated to Falconia by FTDI. + */ +#define FTDI_FALCONIA_JTAG_BUF_PID 0x7150 +#define FTDI_FALCONIA_JTAG_UNBUF_PID 0x7151 +#define FTDI_FALCONIA_DUART28C_PID 0x7152 + /********************************/ /** third-party VID/PID combos **/ From patchwork Wed Sep 16 01:56:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mychaela N. Falconia" X-Patchwork-Id: 11778679 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 569B01580 for ; Wed, 16 Sep 2020 02:06:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3CD1420BED for ; Wed, 16 Sep 2020 02:06:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726146AbgIPCG1 (ORCPT ); Tue, 15 Sep 2020 22:06:27 -0400 Received: from freecalypso.org ([195.154.163.71]:32912 "EHLO freecalypso.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726137AbgIPCGZ (ORCPT ); Tue, 15 Sep 2020 22:06:25 -0400 Received: by freecalypso.org (Postfix, from userid 1001) id 32BAC3740245; Wed, 16 Sep 2020 01:56:37 +0000 (UTC) From: "Mychaela N. Falconia" To: Johan Hovold Cc: linux-usb@vger.kernel.org, mychaela.falconia@gmail.com Subject: [PATCH 2/3] USB: serial: ftdi_sio: pass port to quirk port_probe functions Message-Id: <20200916015637.32BAC3740245@freecalypso.org> Date: Wed, 16 Sep 2020 01:56:36 +0000 (UTC) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The original code passed only the pointer to the ftdi_private struct to quirk port_probe functions. However, some quirks may need to be applied conditionally only to some channels of a multichannel FT2232x or FT4232H device, and if a given quirk's port_probe function needs to figure out which channel of a multichannel device is currently being considered, it needs access to the port pointer passed to the ftdi_sio_port_probe() function, so it can traverse USB data structures from there. Signed-off-by: Mychaela N. Falconia --- drivers/usb/serial/ftdi_sio.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index 8d89a1650dad..cdf4f4e05fb2 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -88,15 +88,17 @@ struct ftdi_private { struct ftdi_sio_quirk { int (*probe)(struct usb_serial *); /* Special settings for probed ports. */ - void (*port_probe)(struct ftdi_private *); + void (*port_probe)(struct usb_serial_port *, struct ftdi_private *); }; static int ftdi_jtag_probe(struct usb_serial *serial); static int ftdi_NDI_device_setup(struct usb_serial *serial); static int ftdi_stmclite_probe(struct usb_serial *serial); static int ftdi_8u2232c_probe(struct usb_serial *serial); -static void ftdi_USB_UIRT_setup(struct ftdi_private *priv); -static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv); +static void ftdi_USB_UIRT_setup(struct usb_serial_port *port, + struct ftdi_private *priv); +static void ftdi_HE_TIRA1_setup(struct usb_serial_port *port, + struct ftdi_private *priv); static const struct ftdi_sio_quirk ftdi_jtag_quirk = { .probe = ftdi_jtag_probe, @@ -2253,7 +2255,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) mutex_init(&priv->cfg_lock); if (quirk && quirk->port_probe) - quirk->port_probe(priv); + quirk->port_probe(port, priv); usb_set_serial_port_data(port, priv); @@ -2277,7 +2279,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port) /* Setup for the USB-UIRT device, which requires hardwired * baudrate (38400 gets mapped to 312500) */ /* Called from usbserial:serial_probe */ -static void ftdi_USB_UIRT_setup(struct ftdi_private *priv) +static void ftdi_USB_UIRT_setup(struct usb_serial_port *port, + struct ftdi_private *priv) { priv->flags |= ASYNC_SPD_CUST; priv->custom_divisor = 77; @@ -2287,7 +2290,8 @@ static void ftdi_USB_UIRT_setup(struct ftdi_private *priv) /* Setup for the HE-TIRA1 device, which requires hardwired * baudrate (38400 gets mapped to 100000) and RTS-CTS enabled. */ -static void ftdi_HE_TIRA1_setup(struct ftdi_private *priv) +static void ftdi_HE_TIRA1_setup(struct usb_serial_port *port, + struct ftdi_private *priv) { priv->flags |= ASYNC_SPD_CUST; priv->custom_divisor = 240; From patchwork Wed Sep 16 01:56:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Mychaela N. Falconia" X-Patchwork-Id: 11778681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C82421580 for ; Wed, 16 Sep 2020 02:06:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BADCE20BED for ; Wed, 16 Sep 2020 02:06:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726168AbgIPCG2 (ORCPT ); Tue, 15 Sep 2020 22:06:28 -0400 Received: from freecalypso.org ([195.154.163.71]:32908 "EHLO freecalypso.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726100AbgIPCGZ (ORCPT ); Tue, 15 Sep 2020 22:06:25 -0400 Received: by freecalypso.org (Postfix, from userid 1001) id B89E1374026F; Wed, 16 Sep 2020 01:56:44 +0000 (UTC) From: "Mychaela N. Falconia" To: Johan Hovold Cc: linux-usb@vger.kernel.org, mychaela.falconia@gmail.com Subject: [PATCH 3/3] USB: serial: ftdi_sio: add support for FreeCalypso DUART28C adapter Message-Id: <20200916015644.B89E1374026F@freecalypso.org> Date: Wed, 16 Sep 2020 01:56:44 +0000 (UTC) Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org FreeCalypso DUART28C is an FT2232D-based USB to dual UART adapter with a special quirk: Channel B RTS and DTR outputs (BDBUS2 and BDBUS4 on the chip) have been repurposed to drive power and reset controls on Calypso targets. The circuit is wired such that BDBUS[24] high (RTS/DTR inactive) is the normal state with power/reset control NOT activated, whereas BDBUS[24] low (RTS or DTR active) turn ON the corresponding power/reset control drivers. A special ftdi_sio driver quirk is needed in order to suppress automatic assertion of DTR & RTS on device open: this device's special power and reset control drivers MUST NOT be activated when the port is ordinarily opened for plain serial communication, instead they must only be activated when a special userspace application explicitly requests such activation with a TIOCMBIS ioctl. The special quirk is conditionalized on the DUART28C adapter's custom USB ID, and is further limited to FT2232D Channel B only: Channel A is wired normally, with the chip's ADBUS2 and ADBUS4 outputs actually being RTS and DTR rather than something else. Signed-off-by: Mychaela N. Falconia --- drivers/usb/serial/ftdi_sio.c | 51 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c index cdf4f4e05fb2..73c6b4e2c3e4 100644 --- a/drivers/usb/serial/ftdi_sio.c +++ b/drivers/usb/serial/ftdi_sio.c @@ -69,6 +69,8 @@ struct ftdi_private { this value */ int force_rtscts; /* if non-zero, force RTS-CTS to always be enabled */ + int no_auto_dtr_rts; /* if non-zero, suppress automatic assertion + of DTR & RTS on device open */ unsigned int latency; /* latency setting in use */ unsigned short max_packet_size; @@ -99,6 +101,8 @@ static void ftdi_USB_UIRT_setup(struct usb_serial_port *port, struct ftdi_private *priv); static void ftdi_HE_TIRA1_setup(struct usb_serial_port *port, struct ftdi_private *priv); +static void ftdi_duart28c_setup(struct usb_serial_port *port, + struct ftdi_private *priv); static const struct ftdi_sio_quirk ftdi_jtag_quirk = { .probe = ftdi_jtag_probe, @@ -124,6 +128,10 @@ static const struct ftdi_sio_quirk ftdi_8u2232c_quirk = { .probe = ftdi_8u2232c_probe, }; +static const struct ftdi_sio_quirk ftdi_duart28c_quirk = { + .port_probe = ftdi_duart28c_setup, +}; + /* * The 8U232AM has the same API as the sio except for: * - it can support MUCH higher baudrates; up to: @@ -1044,6 +1052,8 @@ static const struct usb_device_id id_table_combined[] = { .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_JTAG_UNBUF_PID), .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_DUART28C_PID), + .driver_info = (kernel_ulong_t)&ftdi_duart28c_quirk }, { } /* Terminating entry */ }; @@ -2388,6 +2398,37 @@ static int ftdi_stmclite_probe(struct usb_serial *serial) return 0; } +/* + * FreeCalypso DUART28C is an FT2232D-based USB to dual UART adapter + * with a special quirk: Channel B RTS and DTR outputs (BDBUS2 and BDBUS4 + * on the chip) have been repurposed to drive power and reset controls + * on Calypso targets. The circuit is wired such that BDBUS[24] high + * (RTS/DTR inactive) is the normal state with power/reset control + * NOT activated, whereas BDBUS[24] low (RTS or DTR active) turn ON + * the corresponding power/reset control drivers. + * + * A special ftdi_sio driver quirk is needed in order to suppress + * automatic assertion of DTR & RTS on device open: this device's + * special power and reset control drivers MUST NOT be activated + * when the port is ordinarily opened for plain serial communication, + * instead they must only be activated when a special userspace + * application explicitly requests such activation with a TIOCMBIS ioctl. + * + * The special quirk must be applied only to FT2232D Channel B: + * Channel A is wired normally, with the chip's ADBUS2 and ADBUS4 outputs + * actually being RTS and DTR rather than something else. + */ +static void ftdi_duart28c_setup(struct usb_serial_port *port, + struct ftdi_private *priv) +{ + struct usb_serial *serial = port->serial; + struct usb_device *udev = serial->dev; + struct usb_interface *interface = serial->interface; + + if (interface == udev->actconfig->interface[1]) + priv->no_auto_dtr_rts = 1; +} + static int ftdi_sio_port_remove(struct usb_serial_port *port) { struct ftdi_private *priv = usb_get_serial_port_data(port); @@ -2440,9 +2481,10 @@ static void ftdi_dtr_rts(struct usb_serial_port *port, int on) } } /* drop RTS and DTR */ - if (on) - set_mctrl(port, TIOCM_DTR | TIOCM_RTS); - else + if (on) { + if (!priv->no_auto_dtr_rts) + set_mctrl(port, TIOCM_DTR | TIOCM_RTS); + } else clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); } @@ -2790,7 +2832,8 @@ static void ftdi_set_termios(struct tty_struct *tty, dev_err(ddev, "%s urb failed to set baudrate\n", __func__); mutex_unlock(&priv->cfg_lock); /* Ensure RTS and DTR are raised when baudrate changed from 0 */ - if (old_termios && (old_termios->c_cflag & CBAUD) == B0) + if (old_termios && (old_termios->c_cflag & CBAUD) == B0 + && !priv->no_auto_dtr_rts) set_mctrl(port, TIOCM_DTR | TIOCM_RTS); }