# HG changeset patch # User Mychaela Falconia # Date 1596085964 0 # Node ID 749e1a14aa24ef4b3a4d490bfe637030f5140432 # Parent 5197272cd624f1ca19b833fb7d37f92dfb4d3d94 linux-patch: publishing currently used ftdi_sio driver patch diff -r 5197272cd624 -r 749e1a14aa24 linux-patch/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux-patch/README Thu Jul 30 05:12:44 2020 +0000 @@ -0,0 +1,14 @@ +The patches contained in this directory need to be applied to the Linux kernel +ftdi_sio driver, specifically to ftdi_sio.c and ftdi_sio_ids.h source files. +This patch adds support for Falconia/FreeCalypso custom USB IDs with +appropriate quirks applied: + +* FreeCalypso buffered and unbuffered JTAG+UART adapters are recognized and + treated as such, creating a ttyUSBx device for Channel B, but not for + Channel A. + +* DUART28C USB ID is treated with the appropriate quirk, suppressing automatic + DTR & RTS assertion on ttyUSBx open for Channel B. + +The present patches have been made against Linux kernel version 4.4.14; +application to other kernel versions may require minor porting. diff -r 5197272cd624 -r 749e1a14aa24 linux-patch/ftdi_sio.c.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux-patch/ftdi_sio.c.patch Thu Jul 30 05:12:44 2020 +0000 @@ -0,0 +1,150 @@ +--- ftdi_sio.c.orig 2016-06-24 09:18:38.000000000 -0800 ++++ ftdi_sio.c 2020-07-28 15:33:04.022945400 -0800 +@@ -73,6 +73,8 @@ + 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; +@@ -83,15 +85,19 @@ + 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 void ftdi_duart28c_setup(struct usb_serial_port *port, ++ struct ftdi_private *priv); + + static struct ftdi_sio_quirk ftdi_jtag_quirk = { + .probe = ftdi_jtag_probe, +@@ -117,6 +123,10 @@ + .probe = ftdi_8u2232c_probe, + }; + ++static 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: +@@ -1008,6 +1018,13 @@ + { USB_DEVICE(ICPDAS_VID, ICPDAS_I7560U_PID) }, + { USB_DEVICE(ICPDAS_VID, ICPDAS_I7561U_PID) }, + { USB_DEVICE(ICPDAS_VID, ICPDAS_I7563U_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 }, ++ { USB_DEVICE(FTDI_VID, FTDI_FALCONIA_DUART28C_PID), ++ .driver_info = (kernel_ulong_t)&ftdi_duart28c_quirk }, + { } /* Terminating entry */ + }; + +@@ -1804,7 +1821,7 @@ + priv->flags = ASYNC_LOW_LATENCY; + + if (quirk && quirk->port_probe) +- quirk->port_probe(priv); ++ quirk->port_probe(port, priv); + + usb_set_serial_port_data(port, priv); + +@@ -1820,7 +1837,8 @@ + /* 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; +@@ -1830,7 +1848,8 @@ + /* 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; +@@ -1926,6 +1945,37 @@ + 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); +@@ -1976,9 +2026,10 @@ + } + } + /* 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); + } + +@@ -2316,7 +2367,8 @@ + 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); + } + diff -r 5197272cd624 -r 749e1a14aa24 linux-patch/ftdi_sio_ids.h.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux-patch/ftdi_sio_ids.h.patch Thu Jul 30 05:12:44 2020 +0000 @@ -0,0 +1,17 @@ +--- ftdi_sio_ids.h.orig 2016-06-24 09:18:38.000000000 -0800 ++++ ftdi_sio_ids.h 2020-07-28 14:31:00.550495211 -0800 +@@ -576,6 +576,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 **/