Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1391565

[PATCH v2 2/3] USB: serial: cp210x: Added comments to CRTSCTS flag code.

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v2 2/3] USB: serial: cp210x: Added comments to CRTSCTS flag code.
Date Sat, 30 Apr 2016 04:30:02 +0200
Message-ID <rtsPo-eM-9@gated-at.bofh.it> (permalink)
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=SDFSqHGFPgi8L1tjJ41y3zUhg8WSkBqfC1hd+VzsaAA=; b=aiHrNJ0KyXLG6RaO/klmoyK1a6XyXuYEcdXNBblcvmfF983BcxtGfMIDgEUYLbUIIj YgBfssT/M4s8BiT8768ikRYn6HZgeJBwpb7n8q7hzavvi9HUoesx07EtfdPRBty21Vc4 G7KOu/AfQb/MgoF1ipZtZLwyzSmpAze9O8P+CweEwDEeIdnL/m2em5TYmLu7l0kh9Rkc Nd0nAkgSCOGuMaptYCRNZ97AeYlFgT7iiE5E6GHUfS1v0XmsyIbAnuE8aXiVK7MzMQ3I nqjs+A0vvv/cXddx0fpXB3JXbC73Z3emfhEDs3PkwIkWfFX2jE4OKPDGe1jjeDSPjsdi MeWg==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SDFSqHGFPgi8L1tjJ41y3zUhg8WSkBqfC1hd+VzsaAA=; b=T3bNY9qF0qwhgD9i3wuwAcWxjYJfp+YAUCU70Yx35w/cJY8RQzhGJI6hXWLVH/SlxT U0UAYcqbuc8Ll7uARQNDEEFa26/F89eYEa5DfY88xHSAC9O8JUj/i9AT/KEvuqHUiFR/ PYd+ADuIG+hIOhYpa4l1cqMtl8Rn+96u5HGx9HuNaIHJcoDFnEQ2ka8UrcFK3cfiMp8n k5UsrL0bfId4vU3o7dDajk8PGIuMku9v9jVAv+Z8cv6j1zVGCXHq+m3ULUpzZ2rZw92u hNKa0osSAkHVkQB6SIEeVTKaxrZq1q7maKt7wiqt/0L7ICKRZ4qHsglsneEpqrOAXZx6 giZg==
X-Gm-Message-State AOPr4FV9TXMZZoSe7/HdRMjarbvn3Pkaham+oypm/nmsbTNSGMjaCzQyX8Cd95xQiIvv3A==
X-Received by 10.157.36.100 with SMTP id p91mr11446836ota.124.1461982947188; Fri, 29 Apr 2016 19:22:27 -0700 (PDT)
X-Mailer git-send-email 1.8.4.5
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 153
Organization linux.* mail to news gateway
X-Original-Cc linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com>
X-Original-Date Fri, 29 Apr 2016 21:22:23 -0500
X-Original-Message-ID <1461982943-19664-1-git-send-email-konstantin.shkolnyy@gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1391565

Show key headers only | View raw


Replaced magic numbers used in the CRTSCTS flag code with symbolic names
from the chip specification.

Signed-off-by: Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com>
---
Changes in v2:
Improved CRTSCTS fix based on feedback. Dropped get_termios error handling.

 drivers/usb/serial/cp210x.c | 93 +++++++++++++++++++++++++++++++++------------
 1 file changed, 69 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index abcdb63..da0567c 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -323,6 +323,40 @@ struct cp210x_comm_status {
  */
 #define PURGE_ALL		0x000f
 
+/* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
+struct cp210x_flow_ctl {
+	__le32	ulControlHandshake;
+	__le32	ulFlowReplace;
+	__le32	ulXonLimit;
+	__le32	ulXoffLimit;
+} __packed;
+
+/* cp210x_flow_ctl::ulControlHandshake */
+#define SERIAL_DTR_MASK		0x00000003
+#define SERIAL_CTS_HANDSHAKE	0x00000008
+#define SERIAL_DSR_HANDSHAKE	0x00000010
+#define SERIAL_DCD_HANDSHAKE	0x00000020
+#define SERIAL_DSR_SENSITIVITY	0x00000040
+
+/* values for cp210x_flow_ctl::ulControlHandshake::SERIAL_DTR_MASK */
+#define SERIAL_DTR_INACTIVE	0x00000000
+#define SERIAL_DTR_ACTIVE	0x00000001
+#define SERIAL_DTR_FLOW_CTL	0x00000002
+
+/* cp210x_flow_ctl::ulFlowReplace */
+#define SERIAL_AUTO_TRANSMIT	0x00000001
+#define SERIAL_AUTO_RECEIVE	0x00000002
+#define SERIAL_ERROR_CHAR	0x00000004
+#define SERIAL_NULL_STRIPPING	0x00000008
+#define SERIAL_BREAK_CHAR	0x00000010
+#define SERIAL_RTS_MASK		0x000000c0
+#define SERIAL_XOFF_CONTINUE	0x80000000
+
+/* values for cp210x_flow_ctl::ulFlowReplace::SERIAL_RTS_MASK */
+#define SERIAL_RTS_INACTIVE	0x00000000
+#define SERIAL_RTS_ACTIVE	0x00000040
+#define SERIAL_RTS_FLOW_CTL	0x00000080
+
 /*
  * Reads a variable-sized block of CP210X_ registers, identified by req.
  * Returns data into buf in native USB byte order.
@@ -690,7 +724,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
 {
 	struct device *dev = &port->dev;
 	unsigned int cflag;
-	u8 modem_ctl[16];
+	struct cp210x_flow_ctl flow_ctl;
 	u32 baud;
 	u16 bits;
 
@@ -788,9 +822,9 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
 		break;
 	}
 
-	cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl,
-			sizeof(modem_ctl));
-	if (modem_ctl[0] & 0x08) {
+	cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
+			sizeof(flow_ctl));
+	if (le32_to_cpu(flow_ctl.ulControlHandshake) & SERIAL_CTS_HANDSHAKE) {
 		dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
 		cflag |= CRTSCTS;
 	} else {
@@ -859,7 +893,6 @@ static void cp210x_set_termios(struct tty_struct *tty,
 	struct device *dev = &port->dev;
 	unsigned int cflag, old_cflag;
 	u16 bits;
-	u8 modem_ctl[16];
 
 	cflag = tty->termios.c_cflag;
 	old_cflag = old_termios->c_cflag;
@@ -944,33 +977,45 @@ static void cp210x_set_termios(struct tty_struct *tty,
 
 	if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
 
-		/* Only bytes 0, 4 and 7 out of first 8 have functional bits */
+		struct cp210x_flow_ctl flow_ctl;
+		u32 ControlHandshake;
+		u32 FlowReplace;
 
-		cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl,
-				sizeof(modem_ctl));
-		dev_dbg(dev, "%s - read modem controls = %02x .. .. .. %02x .. .. %02x\n",
-			__func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]);
+		cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
+				sizeof(flow_ctl));
+		ControlHandshake = le32_to_cpu(flow_ctl.ulControlHandshake);
+		FlowReplace      = le32_to_cpu(flow_ctl.ulFlowReplace);
+		dev_dbg(dev, "%s - read ulControlHandshake=%08x ulFlowReplace=%08x\n",
+			__func__, ControlHandshake, FlowReplace);
 
 		if (cflag & CRTSCTS) {
-			modem_ctl[0] &= ~0x7B;
-			modem_ctl[0] |= 0x09;
-			modem_ctl[4] = 0x80;
-			/* FIXME - why clear reserved bits just read? */
-			modem_ctl[5] = 0;
-			modem_ctl[6] = 0;
-			modem_ctl[7] = 0;
+			ControlHandshake &= ~(SERIAL_DTR_MASK |
+				SERIAL_CTS_HANDSHAKE | SERIAL_DSR_HANDSHAKE |
+				SERIAL_DCD_HANDSHAKE | SERIAL_DSR_SENSITIVITY);
+			ControlHandshake |= SERIAL_DTR_ACTIVE;
+			ControlHandshake |= SERIAL_CTS_HANDSHAKE;
+			/* FIXME why clear bits unrelated to flow control */
+			/* FIXME why clear _XOFF_CONTINUE which is never set */
+			FlowReplace &= ~0xffffffff;
+			FlowReplace |= SERIAL_RTS_FLOW_CTL;
 			dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
 		} else {
-			modem_ctl[0] &= ~0x7B;
-			modem_ctl[0] |= 0x01;
-			modem_ctl[4] = 0x40;
+			ControlHandshake &= ~(SERIAL_DTR_MASK |
+				SERIAL_CTS_HANDSHAKE | SERIAL_DSR_HANDSHAKE |
+				SERIAL_DCD_HANDSHAKE | SERIAL_DSR_SENSITIVITY);
+			ControlHandshake |= SERIAL_DTR_ACTIVE;
+			/* FIXME - why clear bits unrelated to flow control */
+			FlowReplace &= ~0xff;
+			FlowReplace |= SERIAL_RTS_ACTIVE;
 			dev_dbg(dev, "%s - flow control = NONE\n", __func__);
 		}
 
-		dev_dbg(dev, "%s - write modem controls = %02x .. .. .. %02x .. .. %02x\n",
-			__func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]);
-		cp210x_write_reg_block(port, CP210X_SET_FLOW, modem_ctl,
-				sizeof(modem_ctl));
+		dev_dbg(dev, "%s - write ulControlHandshake=%08x ulFlowReplace=%08x\n",
+			__func__, ControlHandshake, FlowReplace);
+		flow_ctl.ulControlHandshake = cpu_to_le32(ControlHandshake);
+		flow_ctl.ulFlowReplace      = cpu_to_le32(FlowReplace);
+		cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl,
+				sizeof(flow_ctl));
 	}
 
 }
-- 
1.8.4.5

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[PATCH v2 2/3] USB: serial: cp210x: Added comments to CRTSCTS flag code. Konstantin Shkolnyy <konstantin.shkolnyy@gmail.com> - 2016-04-30 04:30 +0200
  RE: [PATCH v2 2/3] USB: serial: cp210x: Added comments to CRTSCTS  flag code. David Laight <David.Laight@ACULAB.COM> - 2016-05-03 11:50 +0200
    RE: [EXT] RE: [PATCH v2 2/3] USB: serial: cp210x: Added comments to  CRTSCTS flag code. Konstantin Shkolnyy <Konstantin.Shkolnyy@silabs.com> - 2016-05-03 14:20 +0200
      Re: [EXT] RE: [PATCH v2 2/3] USB: serial: cp210x: Added comments to  CRTSCTS flag code. Johan Hovold <johan@kernel.org> - 2016-05-03 14:30 +0200

csiph-web