svn commit: r286385 - in head/sys/dev/usb: . serial

Ian Lepore ian at FreeBSD.org
Thu Aug 6 19:47:05 UTC 2015


Author: ian
Date: Thu Aug  6 19:47:04 2015
New Revision: 286385
URL: https://svnweb.freebsd.org/changeset/base/286385

Log:
  Return the current ftdi bitbang mode with the UFTDIIOC_GET_BITMODE ioctl.
  
  The ftdi chip itself has a "get bitmode" command that doesn't actually
  return the current bitmode, just a snapshot of the gpio lines.  The chip
  apparently has no way to provide the current bitmode.
  
  This implements the functionality at the driver level.  The driver starts
  out assuming the chip is in UART mode (which it will be, coming out of
  reset) and keeps track of every successful set-bitmode operation so that
  it can always return the current mode with UFTDIIOC_GET_BITMODE.

Modified:
  head/sys/dev/usb/serial/uftdi.c
  head/sys/dev/usb/uftdiio.h

Modified: head/sys/dev/usb/serial/uftdi.c
==============================================================================
--- head/sys/dev/usb/serial/uftdi.c	Thu Aug  6 19:45:25 2015	(r286384)
+++ head/sys/dev/usb/serial/uftdi.c	Thu Aug  6 19:47:04 2015	(r286385)
@@ -161,6 +161,7 @@ struct uftdi_softc {
 	uint8_t	sc_hdrlen;
 	uint8_t	sc_msr;
 	uint8_t	sc_lsr;
+	uint8_t sc_bitmode;
 };
 
 struct uftdi_param_config {
@@ -196,7 +197,7 @@ static void	uftdi_cfg_get_status(struct 
 		    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_get_bitmode(struct ucom_softc *, uint8_t *, 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);
@@ -1090,6 +1091,7 @@ uftdi_attach(device_t dev)
 	sc->sc_udev = uaa->device;
 	sc->sc_dev = dev;
 	sc->sc_unit = device_get_unit(dev);
+	sc->sc_bitmode = UFTDI_BITMODE_NONE;
 
 	device_set_usb_desc(dev);
 	mtx_init(&sc->sc_mtx, "uftdi", NULL, MTX_DEF);
@@ -1681,6 +1683,7 @@ uftdi_set_bitmode(struct ucom_softc *uco
 {
 	struct uftdi_softc *sc = ucom->sc_parent;
 	usb_device_request_t req;
+	int rv;
 
 	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
 	req.bRequest = FTDI_SIO_SET_BITMODE;
@@ -1693,11 +1696,15 @@ uftdi_set_bitmode(struct ucom_softc *uco
 	else
 	    USETW2(req.wValue, (1 << bitmode), iomask);
 
-	return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL));
+	rv = usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, NULL);
+	if (rv == USB_ERR_NORMAL_COMPLETION)
+		sc->sc_bitmode = bitmode;
+
+	return (rv);
 }
 
 static int
-uftdi_get_bitmode(struct ucom_softc *ucom, uint8_t *iomask)
+uftdi_get_bitmode(struct ucom_softc *ucom, uint8_t *bitmode, uint8_t *iomask)
 {
 	struct uftdi_softc *sc = ucom->sc_parent;
 	usb_device_request_t req;
@@ -1709,6 +1716,7 @@ uftdi_get_bitmode(struct ucom_softc *uco
 	USETW(req.wLength, 1);
 	USETW(req.wValue,  0);
 
+	*bitmode = sc->sc_bitmode;
 	return (usbd_do_request(sc->sc_udev, &sc->sc_mtx, &req, iomask));
 }
 
@@ -1891,7 +1899,7 @@ uftdi_ioctl(struct ucom_softc *ucom, uin
 		break;
 	case UFTDIIOC_GET_BITMODE:
 		mode = (struct uftdi_bitmode *)data;
-		err = uftdi_get_bitmode(ucom, &mode->iomask);
+		err = uftdi_get_bitmode(ucom, &mode->mode, &mode->iomask);
 		break;
 	case UFTDIIOC_SET_LATENCY:
 		err = uftdi_set_latency(ucom, *((int *)data));

Modified: head/sys/dev/usb/uftdiio.h
==============================================================================
--- head/sys/dev/usb/uftdiio.h	Thu Aug  6 19:45:25 2015	(r286384)
+++ head/sys/dev/usb/uftdiio.h	Thu Aug  6 19:47:04 2015	(r286385)
@@ -43,7 +43,7 @@ enum uftdi_bitmodes
 	UFTDI_BITMODE_CPU_EMUL = 3,
 	UFTDI_BITMODE_FAST_SERIAL = 4,
 	UFTDI_BITMODE_CBUS = 5,
-	UFTDI_BITMODE_NONE = 0xff,
+	UFTDI_BITMODE_NONE = 0xff,	/* aka UART mode. */
 };
 
 /*
@@ -52,8 +52,9 @@ enum uftdi_bitmodes
  *   iomask = Mask of bits enabled for bitbang output.
  *
  * For UFTDIIOC_GET_BITMODE:
- *   mode   = Unused.
- *   iomask = Returned snapshot of bitbang pin states at time of call.
+ *   mode   = Mode most recently set using UFTDIIOC_SET_BITMODE.
+ *   iomask = Returned snapshot of DBUS0..DBUS7 pin states at time of call.
+ *            Pin states can be read in any mode, not just bitbang modes.
  */
 struct uftdi_bitmode
 {


More information about the svn-src-all mailing list