The attached patch, which I hope to commit sometime soon, adds support
for bitbang, MPSSE, CPU_FIFO, and other modes supported by the FTDI
serial adapter chips, using ioctl() calls. This allows full control of
all the FTDI features that embedded folks like, using any language that
supports fd-based IO. You can, for example, program an fpga in MPSSE
mode just by configuring the mode with a couple ioctl() calls, then
writing the bitfile image to the fd as if it were going out a serial
port. You can also do jtag work this way.
In addition to adding the new ioctls, this change removes all the code
that reset the chip at attach and open/close time, and also the code
that turned on RTS/CTS flow control on open without any permission to do
so (that was just always a bug in the driver).
When FTDI chips are configured as GPIO or MPSSE or other special-purpose
uses by an attached serial eeprom, the chip will power on with certain
pins driven or floating, and it's important that the driver not do
anything to the chip to perturb that unless it receives a specific
command to do so. When used for plain old serial comms the chip
powers on into the right mode and never needs to be reset while it's
running to operate properly, so this change is transparent to most
users.
-- Ian
Index: sys/dev/usb/serial/uftdi_reg.h
===
--- sys/dev/usb/serial/uftdi_reg.h (revision 264013)
+++ sys/dev/usb/serial/uftdi_reg.h (working copy)
@@ -28,6 +28,10 @@
* reg */
#define FTDI_SIO_SET_EVENT_CHAR 6 /* Set the event character */
#define FTDI_SIO_SET_ERROR_CHAR 7 /* Set the error character */
+#define FTDI_SIO_SET_LATENCY 9 /* Set the latency timer */
+#define FTDI_SIO_GET_LATENCY 10 /* Read the latency timer */
+#define FTDI_SIO_SET_BITMODE 11 /* Set the bit bang I/O mode */
+#define FTDI_SIO_GET_BITMODE 12 /* Read pin states in bit bang mode */
/* Port Identifier Table */
#define FTDI_PIT_DEFAULT 0 /* SIOA */
Index: sys/dev/usb/serial/uftdi.c
===
--- sys/dev/usb/serial/uftdi.c (revision 264031)
+++ sys/dev/usb/serial/uftdi.c (working copy)
@@ -38,7 +38,14 @@ __FBSDID($FreeBSD$);
*/
/*
- * FTDI FT2232x, FT8U100AX and FT8U232AM serial adapter driver
+ * FTDI FT232x, FT2232x, FT4232x, FT8U100AX and FT8U232xM serial adapters.
+ *
+ * Note that we specifically do not do a reset or otherwise alter the state of
+ * the chip during attach, detach, open, and close, because it could be
+ * pre-initialized (via an attached serial eeprom) to power-on into a mode such
+ * as bitbang in which the pins are being driven to a specific state which we
+ * must not perturb. The device gets reset at power-on, and doesn't need to be
+ * reset again after that to function, except as directed by ioctl() calls.
*/
#include sys/stdint.h
@@ -64,6 +71,7 @@ __FBSDID($FreeBSD$);
#include dev/usb/usbdi.h
#include dev/usb/usbdi_util.h
#include dev/usb/usb_core.h
+#include dev/usb/usb_ioctl.h
#include usbdevs.h
#define USB_DEBUG_VAR uftdi_debug
@@ -72,6 +80,7 @@ __FBSDID($FreeBSD$);
#include dev/usb/serial/usb_serial.h
#include dev/usb/serial/uftdi_reg.h
+#include dev/usb/uftdiio.h
#ifdef USB_DEBUG
static int uftdi_debug = 0;
@@ -175,6 +184,7 @@ static usb_callback_t uftdi_read_callback;
static void uftdi_free(struct ucom_softc *);
static void uftdi_cfg_open(struct ucom_softc *);
+static void uftdi_cfg_close(struct ucom_softc *);
static void uftdi_cfg_set_dtr(struct ucom_softc *, uint8_t);
static void uftdi_cfg_set_rts(struct ucom_softc *, uint8_t);
static void uftdi_cfg_set_break(struct ucom_softc *, uint8_t);
@@ -184,6 +194,15 @@ static int uftdi_pre_param(struct ucom_softc *, st
static void uftdi_cfg_param(struct ucom_softc *, struct termios *);
static void uftdi_cfg_get_status(struct ucom_softc *, uint8_t *,
uint8_t *);
+static int uftdi_reset(struct ucom_softc *, int);
+static int uftdi_set_bitmode(struct ucom_softc *, uint8_t, uint8_t);
+static int uftdi_get_bitmode(struct ucom_softc *, uint8_t *);
+static int uftdi_set_latency(struct ucom_softc *, int);
+static int uftdi_get_latency(struct ucom_softc *, int *);
+static int uftdi_set_event_char(struct ucom_softc *, int);
+static int uftdi_set_error_char(struct ucom_softc *, int);
+static int uftdi_ioctl(struct ucom_softc *, uint32_t, caddr_t, int,
+ struct thread *);
static void uftdi_start_read(struct ucom_softc *);
static void uftdi_stop_read(struct ucom_softc *);
static void uftdi_start_write(struct ucom_softc *);
@@ -218,7 +237,9 @@ static const struct ucom_callback uftdi_callback =
.ucom_cfg_set_break = uftdi_cfg_set_break,
.ucom_cfg_param = uftdi_cfg_param,
.ucom_cfg_open = uftdi_cfg_open,
+ .ucom_cfg_close = uftdi_cfg_close,
.ucom_pre_param = uftdi_pre_param,
+ .ucom_ioctl = uftdi_ioctl,
.ucom_start_read = uftdi_start_read,
.ucom_stop_read = uftdi_stop_read,
.ucom_start_write = uftdi_start_write,