linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 3/3] USB: serial: ftdi_sio: add support for FreeCalypso DUART28C adapter
@ 2020-10-02 18:49 Mychaela N. Falconia
  0 siblings, 0 replies; only message in thread
From: Mychaela N. Falconia @ 2020-10-02 18:49 UTC (permalink / raw)
  To: Johan Hovold; +Cc: linux-usb, mychaela.falconia

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 PWON and RESET controls
on Calypso targets.  The circuit is wired such that BDBUS[24] high
(RTS/DTR inactive) is the normal state with Iota VRPC controls
NOT activated, whereas BDBUS[24] low (RTS or DTR active) turn ON
the corresponding open drain control signal 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 PWON 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.
These special userspace applications are responsible for making the
needed pulse with a TIOCMBIS, delay, TIOCMBIC sequence.

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 <falcon@freecalypso.org>
---

Changes from v1 to v2:

* The logic in the quirk port_probe function for determining which
  interface number is being considered has been changed as asked by
  the reviewer.  The specific magic for retrieving the interface number
  has been copied from the existing ftdi_determine_type() function,
  which is called immediately after quirk->port_probe().

* Comments have been updated in the hope of providing a better
  explanation of how this quirk works in the hardware and why it is
  needed.

Changes from v2 to v3:

* Use cur_altsetting instead of altsetting when accessing
  desc.bInterfaceNumber, specifically use the exact same code
  structure that appears in the JTAG quirk functions after
  the recent cleanup patch.

---
 drivers/usb/serial/ftdi_sio.c     | 61 +++++++++++++++++++++++++++++++++++----
 drivers/usb/serial/ftdi_sio_ids.h |  1 +
 2 files changed, 57 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 31354383a54c..1e49853efbb7 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;
@@ -97,6 +99,7 @@ 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 usb_serial_port *port);
 static void  ftdi_HE_TIRA1_setup(struct usb_serial_port *port);
+static void  ftdi_duart28c_setup(struct usb_serial_port *port);
 
 static const struct ftdi_sio_quirk ftdi_jtag_quirk = {
 	.probe	= ftdi_jtag_probe,
@@ -122,6 +125,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:
@@ -1042,6 +1049,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 */
 };
 
@@ -2386,6 +2395,39 @@ 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 PWON and RESET controls
+ * on Calypso targets.  The circuit is wired such that BDBUS[24] high
+ * (RTS/DTR inactive) is the normal state with Iota VRPC controls
+ * NOT activated, whereas BDBUS[24] low (RTS or DTR active) turn ON
+ * the corresponding open drain control signal 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 PWON 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.
+ * These special userspace applications are responsible for making the
+ * needed pulse with a TIOCMBIS, delay, TIOCMBIC sequence.
+ *
+ * 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 = usb_get_serial_port_data(port);
+	struct usb_serial *serial = port->serial;
+	struct usb_interface *intf = serial->interface;
+	int ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
+
+	if (ifnum == 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);
@@ -2437,10 +2479,18 @@ static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
 			dev_err(&port->dev, "error from flowcontrol urb\n");
 		}
 	}
-	/* drop RTS and DTR */
-	if (on)
-		set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
-	else
+	/*
+	 * Assert or negate RTS and DTR as requested.  When DUART28C
+	 * quirk is applied, we suppress automatic assertion, but
+	 * automatic negation on device close is retained - these
+	 * special control signals are meant to be pulsed, and leaving
+	 * either of them stuck on when the responsible userspace
+	 * program has terminated unexpectedly is undesirable.
+	 */
+	if (on) {
+		if (!priv->no_auto_dtr_rts)
+			set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+	} else
 		clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
 }
 
@@ -2788,7 +2838,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);
 	}
 
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 3d47c6d72256..3081b8916a0a 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -45,6 +45,7 @@
  */
 #define FTDI_FALCONIA_JTAG_BUF_PID	0x7150
 #define FTDI_FALCONIA_JTAG_UNBUF_PID	0x7151
+#define FTDI_FALCONIA_DUART28C_PID	0x7152
 
 /* Sienna Serial Interface by Secyourit GmbH */
 #define FTDI_SIENNA_PID		0x8348
-- 
2.9.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-02 18:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 18:49 [PATCH v3 3/3] USB: serial: ftdi_sio: add support for FreeCalypso DUART28C adapter Mychaela N. Falconia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).