Skip to contentSkip to conversation

: This patch leaves RTS alone when CRTSCTS is not set.

PATCH In review Bryan Wu 3 participants 3 messages May 12, 2008

lore
Share & tools
lore

Bryan Wu

author
#0 lore raw

PATCH 1/1 : This patch leaves RTS alone when CRTSCTS is not set.

From: Oleksiy Kebkal <[email protected]>

Current behaviour doesn't give any possibility to

1. preconfigure port setting, because open operation implies RTS assertion and initial serial port setting may be wrong.

2. realize peculiar serial flow control required by some hardware especially in embedded devices.

---
 drivers/serial/serial_core.c |   42 ++++++++++++++++++++++++++++--------------
 1 files changed, 28 insertions(+), 14 deletions(-)
drivers/serial/serial_core.c +28 -14
index eab0327..903360b 100644
@@ -179,11 +179,15 @@ static int uart_startup(struct uart_state *state, int init_hw)
 			uart_change_speed(state, NULL);
 
 			/*
-			 * Setup the RTS and DTR signals once the
-			 * port is open and ready to respond.
+			 * Setup the RTS (in the case of hardware flow control)
+			 * and DTR signals once the port is open and ready to
+			 * respond.
 			 */
-			if (info->tty->termios->c_cflag & CBAUD)
-				uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
+			if (info->tty->termios->c_cflag & CBAUD) {
+				uart_set_mctrl(port, TIOCM_DTR);
+				if (info->flags & UIF_CTS_FLOW)
+					uart_set_mctrl(port, TIOCM_RTS);
+			}
 		}
 
 		if (info->flags & UIF_CTS_FLOW) {
@@ -224,10 +228,14 @@ static void uart_shutdown(struct uart_state *state)
 		info->flags &= ~UIF_INITIALIZED;
 
 		/*
-		 * Turn off DTR and RTS early.
+		 * Turn off DTR and RTS (in the case of hardware flow control)
+		 * early.
 		 */
-		if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
-			uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+		if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
+			uart_clear_mctrl(port, TIOCM_DTR);
+			if (info->flags & UIF_CTS_FLOW)
+				uart_clear_mctrl(port, TIOCM_RTS);
+               }
 
 		/*
 		 * clear delta_msr_wait queue to avoid mem leaks: we may free
@@ -1190,14 +1198,16 @@ static void uart_set_termios(struct tty_struct *tty,
 	uart_change_speed(state, old_termios);
 
 	/* Handle transition to B0 status */
-	if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
-		uart_clear_mctrl(state->port, TIOCM_RTS | TIOCM_DTR);
+	if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) {
+		uart_clear_mctrl(state->port, TIOCM_DTR);
+		if (state->info->flags & UIF_CTS_FLOW)
+			uart_clear_mctrl(state->port, TIOCM_RTS);
+       }
 
 	/* Handle transition away from B0 status */
 	if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
 		unsigned int mask = TIOCM_DTR;
-		if (!(cflag & CRTSCTS) ||
-		    !test_bit(TTY_THROTTLED, &tty->flags))
+		if (!test_bit(TTY_THROTTLED, &tty->flags))
 			mask |= TIOCM_RTS;
 		uart_set_mctrl(state->port, mask);
 	}
@@ -1441,10 +1451,14 @@ static void uart_update_termios(struct uart_state *state)
 		uart_change_speed(state, NULL);
 
 		/*
-		 * And finally enable the RTS and DTR signals.
+		 * And finally enable the RTS (in the of case hardware flow
+		 * control) and DTR signals.
 		 */
-		if (tty->termios->c_cflag & CBAUD)
-			uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+		if (tty->termios->c_cflag & CBAUD) {
+			uart_set_mctrl(port, TIOCM_DTR);
+			if (state->info->flags & UIF_CTS_FLOW)
+				uart_set_mctrl(port, TIOCM_RTS);
+		}
 	}
 }
 
Signature · 1 line
1.5.5
#1 lore raw

drivers/serial/serial_core.c static int uart_startup(struct uart_state *state, int init_hw) · line 190

Quoted 11 lines
drivers/serial/serial_core.c +8 -2
+			 * Setup the RTS (in the case of hardware flow control)
+			 * and DTR signals once the port is open and ready to
+			 * respond.
 			 */
-			if (info->tty->termios->c_cflag & CBAUD)
-				uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
+			if (info->tty->termios->c_cflag & CBAUD) {
+				uart_set_mctrl(port, TIOCM_DTR);
+				if (info->flags & UIF_CTS_FLOW)
+					uart_set_mctrl(port, TIOCM_RTS);
+			}

Seems fine but we've now got 5 line blocks of duplicated code - and code we will need to complicate further in future if we add other flow control systems.

statc void uart_set_flow_control(port, int onoff)

{
	..
}

Would be worth writing and using for these cases

(Yes I am being fussy: I am currently trying to stamp out lots of code duplication in the tty and serial layers so I don't want more added as it is getting out of hand)

Alan

#2 lore raw
In reply to Bryan Wu
Quoted 9 lines · Bryan Wu
drivers/serial/serial_core.c +0 -1
index eab0327..903360b 100644
@@ -179,11 +179,15 @@ static int uart_startup(struct uart_state *state, int init_hw)
 			uart_change_speed(state, NULL);
 
 			/*
-			 * Setup the RTS and DTR signals once the

drivers/serial/serial_core.c static int uart_startup(struct uart_state *state, int init_hw) · line 188

Quoted 10 lines
drivers/serial/serial_core.c +6 -3
-			 * port is open and ready to respond.
+			 * Setup the RTS (in the case of hardware flow control)
+			 * and DTR signals once the port is open and ready to
+			 * respond.
 			 */
-			if (info->tty->termios->c_cflag & CBAUD)
-				uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
+			if (info->tty->termios->c_cflag & CBAUD) {
+				uart_set_mctrl(port, TIOCM_DTR);
+				if (info->flags & UIF_CTS_FLOW)

We have access to termios->c_cflag here, please use that in preference to testing info->flags.

Quoted 8 lines
drivers/serial/serial_core.c +2 -0
+					uart_set_mctrl(port, TIOCM_RTS);
+			}
 		}
 
 		if (info->flags & UIF_CTS_FLOW) {
@@ -224,10 +228,14 @@ static void uart_shutdown(struct uart_state *state)
 		info->flags &= ~UIF_INITIALIZED;
 

drivers/serial/serial_core.c static void uart_shutdown(struct uart_state *state) · line 236

Quoted 10 lines
drivers/serial/serial_core.c +5 -3
 		/*
-		 * Turn off DTR and RTS early.
+		 * Turn off DTR and RTS (in the case of hardware flow control)
+		 * early.
 		 */
-		if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
-			uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+		if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
+			uart_clear_mctrl(port, TIOCM_DTR);
+			if (info->flags & UIF_CTS_FLOW)

Ditto.

Quoted 6 lines
drivers/serial/serial_core.c +2 -0
+				uart_clear_mctrl(port, TIOCM_RTS);
+               }
 
 		/*
 		 * clear delta_msr_wait queue to avoid mem leaks: we may free

drivers/serial/serial_core.c static void uart_set_termios(struct tty_struct *tty, · line 1203

Quoted 8 lines
drivers/serial/serial_core.c +3 -2
@@ -1190,14 +1198,16 @@ static void uart_set_termios(struct tty_struct *tty,
 	uart_change_speed(state, old_termios);
 
 	/* Handle transition to B0 status */
-	if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
-		uart_clear_mctrl(state->port, TIOCM_RTS | TIOCM_DTR);
+	if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD)) {
+		uart_clear_mctrl(state->port, TIOCM_DTR);
+		if (state->info->flags & UIF_CTS_FLOW)

Ditto.

drivers/serial/serial_core.c static void uart_set_termios(struct tty_struct *tty, · line 1211

Quoted 10 lines
drivers/serial/serial_core.c +3 -2
+			uart_clear_mctrl(state->port, TIOCM_RTS);
+       }
 
 	/* Handle transition away from B0 status */
 	if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
 		unsigned int mask = TIOCM_DTR;
-		if (!(cflag & CRTSCTS) ||
-		    !test_bit(TTY_THROTTLED, &tty->flags))
+		if (!test_bit(TTY_THROTTLED, &tty->flags))
 			mask |= TIOCM_RTS;

This is inconsistent with your other changes - with your change, it will always set RTS when switching away from B0 status.

Quoted 5 lines
drivers/serial/serial_core.c +0 -0
 		uart_set_mctrl(state->port, mask);
 	}
@@ -1441,10 +1451,14 @@ static void uart_update_termios(struct uart_state *state)
 		uart_change_speed(state, NULL);
 

drivers/serial/serial_core.c static void uart_update_termios(struct uart_state *state) · line 1459

Quoted 10 lines
drivers/serial/serial_core.c +5 -3
 		/*
-		 * And finally enable the RTS and DTR signals.
+		 * And finally enable the RTS (in the of case hardware flow
+		 * control) and DTR signals.
 		 */
-		if (tty->termios->c_cflag & CBAUD)
-			uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+		if (tty->termios->c_cflag & CBAUD) {
+			uart_set_mctrl(port, TIOCM_DTR);
+			if (state->info->flags & UIF_CTS_FLOW)

We have access to termios->c_cflag here, please use that in preference to testing info->flags.

Quoted 5 lines
drivers/serial/serial_core.c +2 -0
+				uart_set_mctrl(port, TIOCM_RTS);
+		}
 	}
 }
 
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of: