Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Aug 2012 22:21:47 +0000 (UTC)
From:      Gavin Atkinson <gavin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r239260 - head/sys/dev/usb/serial
Message-ID:  <201208142221.q7EMLlQc058776@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gavin
Date: Tue Aug 14 22:21:46 2012
New Revision: 239260
URL: http://svn.freebsd.org/changeset/base/239260

Log:
  Rename command defines to match names used in the datasheet, in order to
  make maintaining this driver from the documentation easier in the future.
  This is a mostly mechanical change.
  
  In uslcom_param(), move the zeroing of the final two fields of the
  flowctrl structure outside of the "if CRTSCTS" section - not only were
  they being zeroed in both the clauses, but these two fields have nothing
  to do with hardware flow control anyway.

Modified:
  head/sys/dev/usb/serial/uslcom.c

Modified: head/sys/dev/usb/serial/uslcom.c
==============================================================================
--- head/sys/dev/usb/serial/uslcom.c	Tue Aug 14 22:15:12 2012	(r239259)
+++ head/sys/dev/usb/serial/uslcom.c	Tue Aug 14 22:21:46 2012	(r239260)
@@ -19,6 +19,12 @@ __FBSDID("$FreeBSD$");
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+/*
+ * Driver for Silicon Laboratories CP2101/CP2102/CP2103/CP2104/CP2105
+ * USB-Serial adapters.  Based on datasheet AN571, publicly available from
+ * http://www.silabs.com/Support%20Documents/TechnicalDocs/AN571.pdf
+ */
+
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -61,55 +67,54 @@ SYSCTL_INT(_hw_usb_uslcom, OID_AUTO, deb
 #define	USLCOM_BULK_BUF_SIZE		1024
 #define	USLCOM_CONFIG_INDEX	0
 
-#define	USLCOM_SET_DATA_BITS(x)	((x) << 8)
-
 /* Request types */
 #define	USLCOM_WRITE		0x41
 #define	USLCOM_READ		0xc1
 
 /* Request codes */
-#define	USLCOM_UART		0x00
-#define	USLCOM_SET_BAUD_DIV	0x01	
-#define	USLCOM_DATA		0x03
-#define	USLCOM_BREAK		0x05
-#define	USLCOM_CTRL		0x07
-#define	USLCOM_RCTRL            0x08
-#define	USLCOM_SET_FLOWCTRL     0x13
-#define	USLCOM_SET_BAUD_RATE	0x1e	
+#define	USLCOM_IFC_ENABLE	0x00
+#define	USLCOM_SET_BAUDDIV	0x01	
+#define	USLCOM_SET_LINE_CTL	0x03
+#define	USLCOM_SET_BREAK	0x05
+#define	USLCOM_SET_MHS		0x07
+#define	USLCOM_GET_MDMSTS	0x08
+#define	USLCOM_SET_FLOW		0x13
+#define	USLCOM_SET_BAUDRATE	0x1e	
 #define	USLCOM_VENDOR_SPECIFIC	0xff
 
-/* USLCOM_UART values */
-#define	USLCOM_UART_DISABLE	0x00
-#define	USLCOM_UART_ENABLE	0x01
-
-/* USLCOM_CTRL/USLCOM_RCTRL values */
-#define	USLCOM_CTRL_DTR_ON	0x0001	
-#define	USLCOM_CTRL_DTR_SET	0x0100
-#define	USLCOM_CTRL_RTS_ON	0x0002
-#define	USLCOM_CTRL_RTS_SET	0x0200
-#define	USLCOM_CTRL_CTS		0x0010
-#define	USLCOM_CTRL_DSR		0x0020
-#define	USLCOM_CTRL_RI          0x0040
-#define	USLCOM_CTRL_DCD		0x0080
+/* USLCOM_IFC_ENABLE values */
+#define	USLCOM_IFC_ENABLE_DIS	0x00
+#define	USLCOM_IFC_ENABLE_EN	0x01
+
+/* USLCOM_SET_MHS/USLCOM_GET_MDMSTS values */
+#define	USLCOM_MHS_DTR_ON	0x0001	
+#define	USLCOM_MHS_DTR_SET	0x0100
+#define	USLCOM_MHS_RTS_ON	0x0002
+#define	USLCOM_MHS_RTS_SET	0x0200
+#define	USLCOM_MHS_CTS		0x0010
+#define	USLCOM_MHS_DSR		0x0020
+#define	USLCOM_MHS_RI		0x0040
+#define	USLCOM_MHS_DCD		0x0080
 
-/* USLCOM_SET_BAUD_DIV values */
-#define	USLCOM_BAUD_REF		3686400 /* 3.6864 MHz */
+/* USLCOM_SET_BAUDDIV values */
+#define	USLCOM_BAUDDIV_REF	3686400 /* 3.6864 MHz */
 
-/* USLCOM_DATA values */
+/* USLCOM_SET_LINE_CTL values */
 #define	USLCOM_STOP_BITS_1	0x00
 #define	USLCOM_STOP_BITS_2	0x02
 #define	USLCOM_PARITY_NONE	0x00
 #define	USLCOM_PARITY_ODD	0x10
 #define	USLCOM_PARITY_EVEN	0x20
+#define	USLCOM_SET_DATA_BITS(x)	((x) << 8)
 
-/* USLCOM_BREAK values */
-#define	USLCOM_BREAK_OFF	0x00
-#define	USLCOM_BREAK_ON		0x01
+/* USLCOM_SET_BREAK values */
+#define	USLCOM_SET_BREAK_OFF	0x00
+#define	USLCOM_SET_BREAK_ON	0x01
 
-/* USLCOM_SET_FLOWCTRL values - 1st word */
+/* USLCOM_SET_FLOW values - 1st word */
 #define	USLCOM_FLOW_DTR_ON      0x00000001 /* DTR static active */
 #define	USLCOM_FLOW_CTS_HS      0x00000008 /* CTS handshake */
-/* USLCOM_SET_FLOWCTRL values - 2nd word */
+/* USLCOM_SET_FLOW values - 2nd word */
 #define	USLCOM_FLOW_RTS_ON      0x00000040 /* RTS static active */
 #define	USLCOM_FLOW_RTS_HS      0x00000080 /* RTS handshake */
 
@@ -460,8 +465,8 @@ uslcom_open(struct ucom_softc *ucom)
 	struct usb_device_request req;
 
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_UART;
-	USETW(req.wValue, USLCOM_UART_ENABLE);
+	req.bRequest = USLCOM_IFC_ENABLE;
+	USETW(req.wValue, USLCOM_IFC_ENABLE_EN);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, 0);
 
@@ -484,8 +489,8 @@ uslcom_close(struct ucom_softc *ucom)
 	usb_callout_stop(&sc->sc_watchdog);
 
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_UART;
-	USETW(req.wValue, USLCOM_UART_DISABLE);
+	req.bRequest = USLCOM_IFC_ENABLE;
+	USETW(req.wValue, USLCOM_IFC_ENABLE_DIS);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, 0);
 
@@ -504,11 +509,11 @@ uslcom_set_dtr(struct ucom_softc *ucom, 
 
         DPRINTF("onoff = %d\n", onoff);
 
-	ctl = onoff ? USLCOM_CTRL_DTR_ON : 0;
-	ctl |= USLCOM_CTRL_DTR_SET;
+	ctl = onoff ? USLCOM_MHS_DTR_ON : 0;
+	ctl |= USLCOM_MHS_DTR_SET;
 
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_CTRL;
+	req.bRequest = USLCOM_SET_MHS;
 	USETW(req.wValue, ctl);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, 0);
@@ -528,11 +533,11 @@ uslcom_set_rts(struct ucom_softc *ucom, 
 
         DPRINTF("onoff = %d\n", onoff);
 
-	ctl = onoff ? USLCOM_CTRL_RTS_ON : 0;
-	ctl |= USLCOM_CTRL_RTS_SET;
+	ctl = onoff ? USLCOM_MHS_RTS_ON : 0;
+	ctl |= USLCOM_MHS_RTS_SET;
 
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_CTRL;
+	req.bRequest = USLCOM_SET_MHS;
 	USETW(req.wValue, ctl);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, 0);
@@ -563,7 +568,7 @@ uslcom_param(struct ucom_softc *ucom, st
 
 	baudrate = t->c_ospeed;
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_SET_BAUD_RATE;
+	req.bRequest = USLCOM_SET_BAUDRATE;
 	USETW(req.wValue, 0);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, sizeof(baudrate));
@@ -600,7 +605,7 @@ uslcom_param(struct ucom_softc *ucom, st
 	}
 
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_DATA;
+	req.bRequest = USLCOM_SET_LINE_CTL;
 	USETW(req.wValue, data);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, 0);
@@ -613,16 +618,14 @@ uslcom_param(struct ucom_softc *ucom, st
 	if (t->c_cflag & CRTSCTS) {
 		flowctrl[0] = htole32(USLCOM_FLOW_DTR_ON | USLCOM_FLOW_CTS_HS);
 		flowctrl[1] = htole32(USLCOM_FLOW_RTS_HS);
-		flowctrl[2] = 0;
-		flowctrl[3] = 0;
 	} else {
 		flowctrl[0] = htole32(USLCOM_FLOW_DTR_ON);
 		flowctrl[1] = htole32(USLCOM_FLOW_RTS_ON);
-		flowctrl[2] = 0;
-		flowctrl[3] = 0;
 	}
+	flowctrl[2] = 0;
+	flowctrl[3] = 0;
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_SET_FLOWCTRL;
+	req.bRequest = USLCOM_SET_FLOW;
 	USETW(req.wValue, 0);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, sizeof(flowctrl));
@@ -649,10 +652,10 @@ uslcom_set_break(struct ucom_softc *ucom
 {
         struct uslcom_softc *sc = ucom->sc_parent;
 	struct usb_device_request req;
-	uint16_t brk = onoff ? USLCOM_BREAK_ON : USLCOM_BREAK_OFF;
+	uint16_t brk = onoff ? USLCOM_SET_BREAK_ON : USLCOM_SET_BREAK_OFF;
 
 	req.bmRequestType = USLCOM_WRITE;
-	req.bRequest = USLCOM_BREAK;
+	req.bRequest = USLCOM_SET_BREAK;
 	USETW(req.wValue, brk);
 	USETW(req.wIndex, sc->sc_iface_no);
 	USETW(req.wLength, 0);
@@ -787,13 +790,13 @@ uslcom_control_callback(struct usb_xfer 
 	case USB_ST_TRANSFERRED:
 		pc = usbd_xfer_get_frame(xfer, 1);
 		usbd_copy_out(pc, 0, &buf, sizeof(buf));
-		if (buf & USLCOM_CTRL_CTS)
+		if (buf & USLCOM_MHS_CTS)
 			msr |= SER_CTS;
-		if (buf & USLCOM_CTRL_DSR)
+		if (buf & USLCOM_MHS_DSR)
 			msr |= SER_DSR;
-		if (buf & USLCOM_CTRL_RI)
+		if (buf & USLCOM_MHS_RI)
 			msr |= SER_RI;
-		if (buf & USLCOM_CTRL_DCD)
+		if (buf & USLCOM_MHS_DCD)
 			msr |= SER_DCD;
 
 		if (msr != sc->sc_msr) {
@@ -806,7 +809,7 @@ uslcom_control_callback(struct usb_xfer 
 
 	case USB_ST_SETUP:
 		req.bmRequestType = USLCOM_READ;
-		req.bRequest = USLCOM_RCTRL;
+		req.bRequest = USLCOM_GET_MDMSTS;
 		USETW(req.wValue, 0);
 		USETW(req.wIndex, sc->sc_iface_no);
 		USETW(req.wLength, sizeof(buf));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201208142221.q7EMLlQc058776>