Skip to contentSkip to conversation

serial: make hardware flow control more flexible

RFC PATCH New Aristeu Rozanski 1 participant 7 messages Sep 30, 2008

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover serial: make hardware flow control more flexible

This series of patches begins the changes in the serial code to allow more flexible hardware flow control rules. Instead of having fixed models like RTS/CTS or DSR/DTR, the new termiox structure will instead allow to specify which pins will be used.

Currently, termiox has four flags: RTSXOFF, CTSXON, DTRXOFF and DSRXON. This is not yet enough to fully specify Linux' CRTSCTS since it uses the DTR always on while the serial port is available (and RTS to signal if the system is ready or not to receive data). The plan is add RTSON and DTRON to termiox to allow the user to specify that those pins will be always set while the serial port is available.

These patches are not intended for inclusion, just to continue the discussion.

Signature · 1 line
Aristeu
#1 lore raw

RFC PATCH 1/6 serial_core: add termiox support

This patch adds support for termiox on serial_core and implements allocation and freeing of termiox structure in tty_struct if the driver has support for termiox

---
 drivers/char/tty_io.c        |   82 ++++++++++++++++++++++++++++++++++++++-----
 drivers/serial/serial_core.c |   13 ++++++
 include/linux/serial_core.h  |    2 +
 include/linux/tty_driver.h   |    1 
 4 files changed, 90 insertions(+), 8 deletions(-)
drivers/serial/serial_core.c +13 -0
@@ -2292,6 +2292,16 @@ static void uart_poll_put_char(struct tt
 }
 #endif
 
+#ifdef TCSETX
+static int uart_set_termiox(struct tty_struct *tty, struct termiox *new)
+{
+	tty->termiox->x_cflag = new->x_cflag &
+				(RTSXOFF | CTSXON | DTRXOFF | DSRXON);
+
+	return 0;
+}
+#endif
+
 static const struct tty_operations uart_ops = {
 	.open		= uart_open,
 	.close		= uart_close,
@@ -2322,6 +2332,9 @@ static const struct tty_operations uart_
 	.poll_get_char	= uart_poll_get_char,
 	.poll_put_char	= uart_poll_put_char,
 #endif
+#ifdef TCSETX
+	.set_termiox	= uart_set_termiox,
+#endif
 };
 
 /**
include/linux/serial_core.h +2 -0
@@ -190,6 +190,8 @@ struct uart_ops {
 	void		(*flush_buffer)(struct uart_port *);
 	void		(*set_termios)(struct uart_port *, struct ktermios *new,
 				       struct ktermios *old);
+	void		(*set_termiox)(struct uart_port *, struct termiox *new,
+				       struct termiox *old);
 	void		(*set_ldisc)(struct uart_port *);
 	void		(*pm)(struct uart_port *, unsigned int state,
 			      unsigned int oldstate);
drivers/char/tty_io.c +74 -8

146 lines not on this page · raw message

include/linux/tty_driver.h +1 -0
@@ -293,6 +293,7 @@ struct tty_driver {
 	struct tty_struct **ttys;
 	struct ktermios **termios;
 	struct ktermios **termios_locked;
+	struct termiox **termiox;
 	void *driver_state;
 
 	/*
Signature · 1 line
Aristeu
#2 lore raw

RFC PATCH 2/6 serial_core: add separated CTS, RTS, DTR, DSR flow control flags

In reply to Aristeu Rozanski

This patch is the first step to implement hardware flow control using termiox which will allow the user to customize which pins to use for hardware flow control.

---
 include/linux/serial_core.h |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/serial_core.h +5 -1
@@ -288,7 +288,11 @@ struct uart_port {
 #define UPF_LOW_LATENCY		((__force upf_t) (1 << 13))
 #define UPF_BUGGY_UART		((__force upf_t) (1 << 14))
 #define UPF_MAGIC_MULTIPLIER	((__force upf_t) (1 << 16))
-#define UPF_CONS_FLOW		((__force upf_t) (1 << 23))
+#define UPF_FLOW_DTRXOFF	((__force upf_t) (1 << 20))
+#define UPF_FLOW_RTSXOFF	((__force upf_t) (1 << 21))
+#define UPF_FLOW_DSRXON		((__force upf_t) (1 << 22))
+#define UPF_FLOW_CTSXON		((__force upf_t) (1 << 23))
+#define UPF_CONS_FLOW		(UPF_FLOW_RTSXOFF | UPF_FLOW_CTSXON)
 #define UPF_SHARE_IRQ		((__force upf_t) (1 << 24))
 #define UPF_BOOT_AUTOCONF	((__force upf_t) (1 << 28))
 #define UPF_FIXED_PORT		((__force upf_t) (1 << 29))
Signature · 1 line
Aristeu
#3 lore raw

RFC PATCH 3/6 serial_core: use port flags to determine hardware flow control

In reply to Aristeu Rozanski

This patch makes serial_core to use hardware flow port flags instead of using the fixed RTS/CTS.

---
 drivers/serial/serial_core.c |  154 ++++++++++++++++++++++++++++++++++++-------
 include/linux/serial_core.h  |    2 
 2 files changed, 133 insertions(+), 23 deletions(-)
drivers/serial/serial_core.c +131 -23
@@ -133,6 +133,49 @@ uart_update_mctrl(struct uart_port *port
 #define uart_set_mctrl(port, set)	uart_update_mctrl(port, set, 0)
 #define uart_clear_mctrl(port, clear)	uart_update_mctrl(port, 0, clear)
 
+static void uart_flow_input_start(struct uart_port *port)
+{
+	unsigned int bit;
+
+	if (port->flags & UPF_FLOW_RTSXOFF)
+		bit = TIOCM_RTS;
+	else if (port->flags & UPF_FLOW_DTRXOFF)
+		bit = TIOCM_DTR;
+	else
+		return;
+
+	uart_set_mctrl(port, bit);
+}
+
+static void uart_flow_input_stop(struct uart_port *port)
+{
+	unsigned int bit;
+
+	if (port->flags & UPF_FLOW_RTSXOFF)
+		bit = TIOCM_RTS;
+	else if (port->flags & UPF_FLOW_DTRXOFF)
+		bit = TIOCM_DTR;
+	else
+		return;
+
+	uart_clear_mctrl(port, bit);
+}
+
+int uart_flow_output_allowed(struct uart_port *port)
+{
+	unsigned int bit;
+
+	if (port->flags & UPF_FLOW_CTSXON)
+		bit = TIOCM_CTS;
+	else if (port->flags & UPF_FLOW_DSRXON)
+		bit = TIOCM_DSR;
+	else
+		return 1;
+
+	return port->ops->get_mctrl(port) & bit;
+}
+EXPORT_SYMBOL(uart_flow_output_allowed);
+
 /*
  * Startup the port.  This will be called once per open.  All calls
  * will be serialised by the per-port mutex.
@@ -183,16 +226,16 @@ static int uart_startup(struct uart_stat
 			 * Setup the RTS and DTR signals once the
 			 * port is open and ready to respond.
 			 */
-			if (info->port.tty->termios->c_cflag & CBAUD)
-				uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
+			if (info->port.tty->termios->c_cflag & CBAUD) {
+				uart_set_mctrl(port, TIOCM_DTR);
+				uart_flow_input_start(port);
+			}
 		}
 
-		if (info->flags & UIF_CTS_FLOW) {
-			spin_lock_irq(&port->lock);
-			if (!(port->ops->get_mctrl(port) & TIOCM_CTS))
-				info->port.tty->hw_stopped = 1;
-			spin_unlock_irq(&port->lock);
-		}
+		spin_lock_irq(&port->lock);
+		if (!uart_flow_output_allowed(port))
+			info->port.tty->hw_stopped = 1;
+		spin_unlock_irq(&port->lock);
 
 		info->flags |= UIF_INITIALIZED;
 
@@ -609,8 +652,7 @@ static void uart_throttle(struct tty_str
 	if (I_IXOFF(tty))
 		uart_send_xchar(tty, STOP_CHAR(tty));
 
-	if (tty->termios->c_cflag & CRTSCTS)
-		uart_clear_mctrl(state->port, TIOCM_RTS);
+	uart_flow_input_stop(state->port);
 }
 
 static void uart_unthrottle(struct tty_struct *tty)
@@ -625,8 +667,7 @@ static void uart_unthrottle(struct tty_s
 			uart_send_xchar(tty, START_CHAR(tty));
 	}
 
-	if (tty->termios->c_cflag & CRTSCTS)
-		uart_set_mctrl(port, TIOCM_RTS);
+	uart_flow_input_start(port);
 }
 
 static int uart_get_info(struct uart_state *state,
@@ -1208,25 +1249,33 @@ static void uart_set_termios(struct tty_
 
 	/* 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))
-			mask |= TIOCM_RTS;
-		uart_set_mctrl(state->port, mask);
+		uart_set_mctrl(state->port, TIOCM_DTR);
+		if (!test_bit(TTY_THROTTLED, &tty->flags))
+			uart_flow_input_start(state->port);
 	}
 
 	/* Handle turning off CRTSCTS */
 	if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
 		spin_lock_irqsave(&state->port->lock, flags);
-		tty->hw_stopped = 0;
-		__uart_start(tty);
+		tty->termiox->x_cflag &= ~(RTSXOFF | CTSXON);
+		state->port->flags &= ~(UPF_FLOW_RTSXOFF | UPF_FLOW_CTSXON);
+		if (uart_flow_output_allowed(state->port)) {
+			tty->hw_stopped = 0;
+			__uart_start(tty);
+		}
 		spin_unlock_irqrestore(&state->port->lock, flags);
 	}
 
 	/* Handle turning on CRTSCTS */
 	if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
 		spin_lock_irqsave(&state->port->lock, flags);
-		if (!(state->port->ops->get_mctrl(state->port) & TIOCM_CTS)) {
+		tty->termiox->x_cflag |= (RTSXOFF | CTSXON);
+		state->port->flags |= (UPF_FLOW_RTSXOFF | UPF_FLOW_CTSXON);
+		/* not supported right now */
+		tty->termiox->x_cflag &= ~(DTRXOFF | DSRXON);
+		state->port->flags &= ~(UPF_FLOW_DTRXOFF | UPF_FLOW_DSRXON);
+
+		if (!uart_flow_output_allowed(state->port)) {
 			tty->hw_stopped = 1;
 			state->port->ops->stop_tx(state->port);
 		}
@@ -1454,10 +1503,12 @@ static void uart_update_termios(struct u
 		uart_change_speed(state, NULL);
 
 		/*
-		 * And finally enable the RTS and DTR signals.
+		 * And finally enable the DTR signal.
 		 */
-		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);
+			uart_flow_input_start(port);
+		}
 	}
 }
 
@@ -2295,9 +2346,66 @@ static void uart_poll_put_char(struct tt
 #ifdef TCSETX
 static int uart_set_termiox(struct tty_struct *tty, struct termiox *new)
 {
+	struct uart_state *state = tty->driver_data;
+	struct ktermios old_termios;
+	unsigned long flags;
+
+	if (((new->x_cflag & RTSXOFF) && (new->x_cflag & DTRXOFF)) ||
+	    ((new->x_cflag & CTSXON) && (new->x_cflag & DSRXON)))
+		/* not supported (yet?) */
+		return 1;
+
+	/* saving current settings */
+	memcpy(&old_termios, tty->termios, sizeof(old_termios));
+
+	/* stop input flow control */
+	uart_flow_input_stop(state->port);
+
+	/* import the settings */
 	tty->termiox->x_cflag = new->x_cflag &
 				(RTSXOFF | CTSXON | DTRXOFF | DSRXON);
 
+	state->port->flags = 0;
+	if (new->x_cflag & RTSXOFF)
+		state->port->flags |= UPF_FLOW_RTSXOFF;
+	if (new->x_cflag & CTSXON)
+		state->port->flags |= UPF_FLOW_CTSXON;
+	if (new->x_cflag & DTRXOFF)
+		state->port->flags |= UPF_FLOW_DTRXOFF;
+	if (new->x_cflag & DSRXON)
+		state->port->flags |= UPF_FLOW_DSRXON;
+	if (new->x_cflag != (RTSXOFF | CTSXON))
+		tty->termios->c_cflag &= ~CRTSCTS;
+
+	/*
+	 * we need to call uart_change_speed() to propagate the changes like
+	 * disabling CRTSCTS and enabling/disabling interrupts
+	 */
+	uart_change_speed(state, &old_termios);
+
+	/* and restart it if it's possible */
+	if ((tty->termios->c_cflag & CBAUD) &&
+	    !(test_bit(TTY_THROTTLED, &tty->flags)))
+		uart_flow_input_start(state->port);
+
+	/*
+	 * if the TX wasn't enabled before and now it's possible to transmit
+	 * due the changes, do it
+	 */
+	if (tty->hw_stopped && uart_flow_output_allowed(state->port)) {
+		spin_lock_irqsave(&state->port->lock, flags);
+		tty->hw_stopped = 0;
+		__uart_start(tty);
+		spin_unlock_irqrestore(&state->port->lock, flags);
+	} else if (!tty->hw_stopped) {
+		spin_lock_irqsave(&state->port->lock, flags);
+		if (!uart_flow_output_allowed(state->port)) {
+			tty->hw_stopped = 1;
+			state->port->ops->stop_tx(state->port);
+		}
+		spin_unlock_irqrestore(&state->port->lock, flags);
+	}
+
 	return 0;
 }
 #endif
include/linux/serial_core.h +2 -0
@@ -558,6 +558,8 @@ uart_insert_char(struct uart_port *port,
 		tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 }
 
+int uart_flow_output_allowed(struct uart_port *port);
+
 /*
  *	UART_ENABLE_MS - determine if port should enable modem status irqs
  */
Signature · 1 line
Aristeu
#4 lore raw

RFC PATCH 4/6 serial: introduce uart_handle_dsr_change()

In reply to Aristeu Rozanski

This patch introduces uart_handle_dsr_change() and change drivers to use it. Currently the drivers will simply count the DSR changes but won't report this to the serial_core. This is needed for using DSR for flow control.

---
 drivers/serial/8250.c          |    2 -
 drivers/serial/amba-pl010.c    |    2 -
 drivers/serial/amba-pl011.c    |    2 -
 drivers/serial/atmel_serial.c  |    2 -
 drivers/serial/dz.c            |    2 -
 drivers/serial/icom.c          |    7 ++---
 drivers/serial/imx.c           |    2 -
 drivers/serial/ip22zilog.c     |    4 +-
 drivers/serial/pmac_zilog.c    |    4 +-
 drivers/serial/pnx8xxx_uart.c  |    2 -
 drivers/serial/pxa.c           |    2 -
 drivers/serial/sa1100.c        |    2 -
 drivers/serial/sb1250-duart.c  |    2 -
 drivers/serial/serial_ks8695.c |    2 -
 drivers/serial/sunsab.c        |    2 -
 drivers/serial/sunsu.c         |    2 -
 drivers/serial/sunzilog.c      |    4 +-
 drivers/serial/vr41xx_siu.c    |    2 -
 drivers/serial/zs.c            |    5 ++-
 include/linux/serial_core.h    |   55 ++++++++++++++++++++++++++++-------------
 20 files changed, 65 insertions(+), 42 deletions(-)
include/linux/serial_core.h +38 -17
@@ -510,6 +510,43 @@ uart_handle_dcd_change(struct uart_port 
 	}
 }
 
+static inline void
+uart_handle_flow_control_change(struct uart_port *port, unsigned int pin,
+				unsigned int status)
+{
+	struct uart_info *info = port->info;
+	struct tty_struct *tty = info->port.tty;
+
+	if (!(pin & port->flags))
+		return;
+
+	if (tty->hw_stopped) {
+		if (status) {
+			tty->hw_stopped = 0;
+			port->ops->start_tx(port);
+			uart_write_wakeup(port);
+		}
+	} else {
+		if (!status) {
+			tty->hw_stopped = 1;
+			port->ops->stop_tx(port);
+		}
+	}
+}
+
+/**
+ *	uart_handle_dsr_change - handle a change of data-set-ready state
+ *	@port: uart_port structure for the open port
+ *	@status: new clear to send status, nonzero if active
+ */
+static inline void
+uart_handle_dsr_change(struct uart_port *port, unsigned int status)
+{
+	port->icount.dsr++;
+
+	uart_handle_flow_control_change(port, UPF_FLOW_DSRXON, status);
+}
+
 /**
  *	uart_handle_cts_change - handle a change of clear-to-send state
  *	@port: uart_port structure for the open port
@@ -518,25 +555,9 @@ uart_handle_dcd_change(struct uart_port 
 static inline void
 uart_handle_cts_change(struct uart_port *port, unsigned int status)
 {
-	struct uart_info *info = port->info;
-	struct tty_struct *tty = info->port.tty;
-
 	port->icount.cts++;
 
-	if (info->flags & UIF_CTS_FLOW) {
-		if (tty->hw_stopped) {
-			if (status) {
-				tty->hw_stopped = 0;
-				port->ops->start_tx(port);
-				uart_write_wakeup(port);
-			}
-		} else {
-			if (!status) {
-				tty->hw_stopped = 1;
-				port->ops->stop_tx(port);
-			}
-		}
-	}
+	uart_handle_flow_control_change(port, UPF_FLOW_CTSXON, status);
 }
 
 #include <linux/tty_flip.h>
drivers/serial/8250.c +1 -1
@@ -1413,7 +1413,7 @@ static unsigned int check_modem_status(s
 		if (status & UART_MSR_TERI)
 			up->port.icount.rng++;
 		if (status & UART_MSR_DDSR)
-			up->port.icount.dsr++;
+			uart_handle_dsr_change(&up->port, status & UART_MSR_DSR);
 		if (status & UART_MSR_DDCD)
 			uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
 		if (status & UART_MSR_DCTS)
drivers/serial/amba-pl010.c +1 -1
@@ -220,7 +220,7 @@ static void pl010_modem_status(struct ua
 		uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD);
 
 	if (delta & UART01x_FR_DSR)
-		uap->port.icount.dsr++;
+		uart_handle_dsr_change(&uap->port, status & UART01x_FR_DSR);
 
 	if (delta & UART01x_FR_CTS)
 		uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
drivers/serial/amba-pl011.c +1 -1
@@ -204,7 +204,7 @@ static void pl011_modem_status(struct ua
 		uart_handle_dcd_change(&uap->port, status & UART01x_FR_DCD);
 
 	if (delta & UART01x_FR_DSR)
-		uap->port.icount.dsr++;
+		uart_handle_dsr_change(&uap->port, status & UART01x_FR_DSR);
 
 	if (delta & UART01x_FR_CTS)
 		uart_handle_cts_change(&uap->port, status & UART01x_FR_CTS);
drivers/serial/atmel_serial.c +1 -1
@@ -769,7 +769,7 @@ static void atmel_tasklet_func(unsigned 
 		if (status_change & ATMEL_US_RI)
 			port->icount.rng++;
 		if (status_change & ATMEL_US_DSR)
-			port->icount.dsr++;
+			uart_handle_dsr_change(port, !(status & ATMEL_US_DSR));
 		if (status_change & ATMEL_US_DCD)
 			uart_handle_dcd_change(port, !(status & ATMEL_US_DCD));
 		if (status_change & ATMEL_US_CTS)
drivers/serial/dz.c +1 -1
@@ -329,7 +329,7 @@ static inline void check_modem_status(st
 
 	/* it's easy, since DSR2 is the only bit in the register */
 	if (status)
-		dport->port.icount.dsr++;
+		uart_handle_dsr_change(dport->port, status);
 }
 
 /*
drivers/serial/icom.c +4 -3
@@ -681,13 +681,14 @@ static inline void check_modem_status(st
 		if (delta_status & ICOM_RI)
 			icom_port->uart_port.icount.rng++;
 		if (delta_status & ICOM_DSR)
-			icom_port->uart_port.icount.dsr++;
+			uart_handle_dsr_change(&icom_port->uart_port,
+					       status & ICOM_DSR);
 		if (delta_status & ICOM_DCD)
 			uart_handle_dcd_change(&icom_port->uart_port,
-					       delta_status & ICOM_DCD);
+					       status & ICOM_DCD);
 		if (delta_status & ICOM_CTS)
 			uart_handle_cts_change(&icom_port->uart_port,
-					       delta_status & ICOM_CTS);
+					       status & ICOM_CTS);
 
 		wake_up_interruptible(&icom_port->uart_port.info->
 				      delta_msr_wait);
drivers/serial/imx.c +1 -1
@@ -233,7 +233,7 @@ static void imx_mctrl_check(struct imx_p
 	if (changed & TIOCM_RI)
 		sport->port.icount.rng++;
 	if (changed & TIOCM_DSR)
-		sport->port.icount.dsr++;
+		uart_handle_dsr_change(&sport->port, status & TIOCM_DSR);
 	if (changed & TIOCM_CAR)
 		uart_handle_dcd_change(&sport->port, status & TIOCM_CAR);
 	if (changed & TIOCM_CTS)
drivers/serial/ip22zilog.c +2 -2
@@ -340,8 +340,8 @@ static void ip22zilog_status_handle(stru
 	}
 
 	if (ZS_WANTS_MODEM_STATUS(up)) {
-		if (status & SYNC)
-			up->port.icount.dsr++;
+		if ((status ^ up->prev_status) ^ SYNC)
+			uart_handle_dsr_change(&up->port, status & SYNC);
 
 		/* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
 		 * But it does not tell us which bit has changed, we have to keep
drivers/serial/pmac_zilog.c +2 -2
@@ -354,8 +354,8 @@ static void pmz_status_handle(struct uar
 	zssync(uap);
 
 	if (ZS_IS_OPEN(uap) && ZS_WANTS_MODEM_STATUS(uap)) {
-		if (status & SYNC_HUNT)
-			uap->port.icount.dsr++;
+		if ((status ^ uap->prev_status) & SYNC)
+			uart_handle_dsr_change(&uap->port, status & SYNC);
 
 		/* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
 		 * But it does not tell us which bit has changed, we have to keep
drivers/serial/pnx8xxx_uart.c +1 -1
@@ -94,7 +94,7 @@ static void pnx8xxx_mctrl_check(struct p
 	if (changed & TIOCM_RI)
 		sport->port.icount.rng++;
 	if (changed & TIOCM_DSR)
-		sport->port.icount.dsr++;
+		uart_handle_dsr_change(&sport->port, status & TIOCM_DSR);
 	if (changed & TIOCM_CAR)
 		uart_handle_dcd_change(&sport->port, status & TIOCM_CAR);
 	if (changed & TIOCM_CTS)
drivers/serial/sa1100.c +1 -1
@@ -111,7 +111,7 @@ static void sa1100_mctrl_check(struct sa
 	if (changed & TIOCM_RI)
 		sport->port.icount.rng++;
 	if (changed & TIOCM_DSR)
-		sport->port.icount.dsr++;
+		uart_handle_dsr_change(&sport->port, status & TIOCM_DSR);
 	if (changed & TIOCM_CAR)
 		uart_handle_dcd_change(&sport->port, status & TIOCM_CAR);
 	if (changed & TIOCM_CTS)
drivers/serial/sb1250-duart.c +1 -1
@@ -436,7 +436,7 @@ static void sbd_status_handle(struct sbd
 		uart_handle_cts_change(uport, !(delta & M_DUART_IN_PIN0_VAL));
 
 	if (delta & (M_DUART_IN_PIN2_VAL << S_DUART_IN_PIN_CHNG))
-		uport->icount.dsr++;
+		uart_handle_dsr_change(uport, !(delta & M_DUART_IN_PIN2_VAL));
 
 	if (delta & ((M_DUART_IN_PIN2_VAL | M_DUART_IN_PIN0_VAL) <<
 		     S_DUART_IN_PIN_CHNG))
drivers/serial/serial_ks8695.c +1 -1
@@ -212,7 +212,7 @@ static irqreturn_t ks8695uart_modem_stat
 		uart_handle_dcd_change(port, status & URMS_URDDCD);
 
 	if (status & URMS_URDDST)
-		port->icount.dsr++;
+		uart_handle_dsr_change(port, status & URMS_URDDST);
 
 	if (status & URMS_URDCTS)
 		uart_handle_cts_change(port, status & URMS_URDCTS);
drivers/serial/sunsab.c +1 -1
@@ -294,7 +294,7 @@ static void check_status(struct uart_sun
 
 	if ((readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ^ up->dsr) {
 		up->dsr = (readb(&up->regs->r.pvr) & up->pvr_dsr_bit) ? 0 : 1;
-		up->port.icount.dsr++;
+		uart_handle_dsr_change(&up->port, up->dsr);
 	}
 
 	wake_up_interruptible(&up->port.info->delta_msr_wait);
drivers/serial/sunzilog.c +2 -2
@@ -437,8 +437,8 @@ static void sunzilog_status_handle(struc
 	}
 
 	if (ZS_WANTS_MODEM_STATUS(up)) {
-		if (status & SYNC)
-			up->port.icount.dsr++;
+		if ((status ^ up->prev_status) ^ SYNC)
+			uart_handle_dsr_change(&up->port, status & SYNC);
 
 		/* The Zilog just gives us an interrupt when DCD/CTS/etc. change.
 		 * But it does not tell us which bit has changed, we have to keep
drivers/serial/zs.c +3 -2
@@ -681,9 +681,10 @@ static void zs_status_handle(struct zs_p
 			uart_handle_dcd_change(uport,
 					       zport->mctrl & TIOCM_CAR);
 		if (delta & TIOCM_RNG)
-			uport->icount.dsr++;
-		if (delta & TIOCM_DSR)
 			uport->icount.rng++;
+		if (delta & TIOCM_DSR)
+			uart_handle_dsr_change(uport,
+					       zport->mctrl & TIOCM_DSR);
 
 		if (delta)
 			wake_up_interruptible(&uport->info->delta_msr_wait);
drivers/serial/pxa.c +1 -1
@@ -219,7 +219,7 @@ static inline void check_modem_status(st
 	if (status & UART_MSR_TERI)
 		up->port.icount.rng++;
 	if (status & UART_MSR_DDSR)
-		up->port.icount.dsr++;
+		uart_handle_dsr_change(&up->port, status & UART_MSR_DSR);
 	if (status & UART_MSR_DDCD)
 		uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
 	if (status & UART_MSR_DCTS)
drivers/serial/sunsu.c +1 -1
@@ -435,7 +435,7 @@ static void check_modem_status(struct ua
 	if (status & UART_MSR_TERI)
 		up->port.icount.rng++;
 	if (status & UART_MSR_DDSR)
-		up->port.icount.dsr++;
+		uart_handle_dsr_change(&up->port, status & UART_MSR_DSR);
 	if (status & UART_MSR_DDCD)
 		uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
 	if (status & UART_MSR_DCTS)
drivers/serial/vr41xx_siu.c +1 -1
@@ -382,7 +382,7 @@ static inline void check_modem_status(st
 	if (msr & UART_MSR_TERI)
 		port->icount.rng++;
 	if (msr & UART_MSR_DDSR)
-		port->icount.dsr++;
+		uart_handle_dsr_change(port, msr & UART_MSR_DSR);
 	if (msr & UART_MSR_DCTS)
 		uart_handle_cts_change(port, msr & UART_MSR_CTS);
 
Signature · 1 line
Aristeu
#5 lore raw

RFC PATCH 5/6 serial_core: dont assert DTR pin when its being used for flow control

In reply to Aristeu Rozanski

By default, serial_core will assert DTR for compatibility. In the case DTR is being used for flow control this should not happen.

---
 drivers/serial/serial_core.c |   25 ++++++++++++++++++-------
 include/linux/serial_core.h  |   10 +++++++---
 2 files changed, 25 insertions(+), 10 deletions(-)
drivers/serial/serial_core.c +18 -7
@@ -227,7 +227,9 @@ static int uart_startup(struct uart_stat
 			 * port is open and ready to respond.
 			 */
 			if (info->port.tty->termios->c_cflag & CBAUD) {
-				uart_set_mctrl(port, TIOCM_DTR);
+				if (!(info->port.tty->termiox->x_cflag &
+								 DTRXOFF))
+					uart_set_mctrl(port, TIOCM_DTR);
 				uart_flow_input_start(port);
 			}
 		}
@@ -1249,7 +1251,12 @@ static void uart_set_termios(struct tty_
 
 	/* Handle transition away from B0 status */
 	if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
-		uart_set_mctrl(state->port, TIOCM_DTR);
+		/*
+		 * by default, we keep DTR on all the time, except
+		 * when DTR is being used for flow control
+		 */
+		if (!(tty->termiox->x_cflag & DTRXOFF))
+			uart_set_mctrl(state->port, TIOCM_DTR);
 		if (!test_bit(TTY_THROTTLED, &tty->flags))
 			uart_flow_input_start(state->port);
 	}
@@ -1506,7 +1513,8 @@ static void uart_update_termios(struct u
 		 * And finally enable the DTR signal.
 		 */
 		if (tty->termios->c_cflag & CBAUD) {
-			uart_set_mctrl(port, TIOCM_DTR);
+			if (!(tty->termiox->x_cflag & DTRXOFF))
+				uart_set_mctrl(port, TIOCM_DTR);
 			uart_flow_input_start(port);
 		}
 	}
@@ -1562,7 +1570,8 @@ uart_block_til_ready(struct file *filp, 
 		 * not set RTS here - we want to make sure we catch
 		 * the data from the modem.
 		 */
-		if (info->port.tty->termios->c_cflag & CBAUD)
+		if (info->port.tty->termios->c_cflag & CBAUD &&
+		    !(info->port.tty->termiox->x_cflag & DTRXOFF))
 			uart_set_mctrl(port, TIOCM_DTR);
 
 		/*
@@ -2268,9 +2277,11 @@ uart_configure_port(struct uart_driver *
 		 * keep the DTR setting that is set in uart_set_options()
 		 * We probably don't need a spinlock around this, but
 		 */
-		spin_lock_irqsave(&port->lock, flags);
-		port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR);
-		spin_unlock_irqrestore(&port->lock, flags);
+		if (!(port->flags & UPF_FLOW_DTRXOFF)) {
+			spin_lock_irqsave(&port->lock, flags);
+			port->ops->set_mctrl(port, port->mctrl & TIOCM_DTR);
+			spin_unlock_irqrestore(&port->lock, flags);
+		}
 
 		/*
 		 * If this driver supports console, and it hasn't been
include/linux/serial_core.h +7 -3
@@ -581,12 +581,16 @@ uart_insert_char(struct uart_port *port,
 
 int uart_flow_output_allowed(struct uart_port *port);
 
+#define uart_has_hw_flow_control(p) ((p)->flags & (UPF_FLOW_DTRXOFF | \
+						   UPF_FLOW_RTSXOFF | \
+						   UPF_FLOW_DSRXON | \
+						   UPF_FLOW_CTSXON))
 /*
  *	UART_ENABLE_MS - determine if port should enable modem status irqs
  */
-#define UART_ENABLE_MS(port,cflag)	((port)->flags & UPF_HARDPPS_CD || \
-					 (cflag) & CRTSCTS || \
-					 !((cflag) & CLOCAL))
+#define UART_ENABLE_MS(p,cflag)	((p)->flags & UPF_HARDPPS_CD || \
+				 uart_has_hw_flow_control(p) || \
+				 !((cflag) & CLOCAL))
 
 #endif
 
Signature · 1 line
Aristeu
#6 lore raw

RFC PATCH 6/6 serial: convert drivers to use uart_flow_output_allowed()

In reply to Aristeu Rozanski

This patch modifies serial drivers to use uart_flow_output_allowed() making the flow control decision to serial_core.

---
 drivers/serial/8250.c        |   18 +++++++-----------
 drivers/serial/pxa.c         |   12 ++++++------
 drivers/serial/samsung.c     |    6 +++---
 drivers/serial/serial_txx9.c |   12 ++++++------
 drivers/serial/sunsu.c       |   12 ++++++------
 drivers/serial/vr41xx_siu.c  |   15 ++++++---------
 6 files changed, 34 insertions(+), 41 deletions(-)
drivers/serial/8250.c +7 -11
@@ -1779,17 +1779,13 @@ static void wait_for_xmitr(struct uart_8
 	} while ((status & bits) != bits);
 
 	/* Wait up to 1s for flow control if necessary */
-	if (up->port.flags & UPF_CONS_FLOW) {
-		unsigned int tmout;
-		for (tmout = 1000000; tmout; tmout--) {
-			unsigned int msr = serial_in(up, UART_MSR);
-			up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
-			if (msr & UART_MSR_CTS)
-				break;
-			udelay(1);
-			touch_nmi_watchdog();
-		}
-	}
+	tmout = 1000000;
+	do {
+		if (uart_flow_output_allowed(&up->port))
+			break;
+		udelay(1);
+		touch_nmi_watchdog();
+	} while(tmout--);
 }
 
 #ifdef CONFIG_CONSOLE_POLL
drivers/serial/pxa.c +6 -6
@@ -617,12 +617,12 @@ static inline void wait_for_xmitr(struct
 	} while ((status & BOTH_EMPTY) != BOTH_EMPTY);
 
 	/* Wait up to 1s for flow control if necessary */
-	if (up->port.flags & UPF_CONS_FLOW) {
-		tmout = 1000000;
-		while (--tmout &&
-		       ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
-			udelay(1);
-	}
+	tmout = 1000000;
+	do {
+		if (uart_flow_output_allowed(&up->port))
+			break;
+		udelay(1);
+	} while(tmout--);
 }
 
 static void serial_pxa_console_putchar(struct uart_port *port, int ch)
drivers/serial/serial_txx9.c +6 -6
@@ -475,12 +475,12 @@ static void wait_for_xmitr(struct uart_t
 		udelay(1);
 
 	/* Wait up to 1s for flow control if necessary */
-	if (up->port.flags & UPF_CONS_FLOW) {
-		tmout = 1000000;
-		while (--tmout &&
-		       (sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS))
-			udelay(1);
-	}
+	tmout = 1000000;
+	do {
+		if (uart_flow_output_allowed(&up->port))
+			break;
+		udelay(1);
+	} while(tmout--);
 }
 #endif
 
drivers/serial/sunsu.c +6 -6
@@ -1265,12 +1265,12 @@ static __inline__ void wait_for_xmitr(st
 	} while ((status & BOTH_EMPTY) != BOTH_EMPTY);
 
 	/* Wait up to 1s for flow control if necessary */
-	if (up->port.flags & UPF_CONS_FLOW) {
-		tmout = 1000000;
-		while (--tmout &&
-		       ((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
-			udelay(1);
-	}
+	tmout = 1000000;
+	do {
+		if (uart_flow_output_allowed(&up->port))
+			break;
+		udelay(1);
+	} while(tmout--);
 }
 
 static void sunsu_console_putchar(struct uart_port *port, int ch)
drivers/serial/vr41xx_siu.c +6 -9
@@ -751,15 +751,12 @@ static void wait_for_xmitr(struct uart_p
 			break;
 	} while (timeout-- > 0);
 
-	if (port->flags & UPF_CONS_FLOW) {
-		timeout = 1000000;
-
-		do {
-			msr = siu_read(port, UART_MSR);
-			if ((msr & UART_MSR_CTS) != 0)
-				break;
-		} while (timeout-- > 0);
-	}
+	timeout = 1000000;
+	do {
+		if (uart_flow_output_allowed(port))
+			break;
+		udelay(1);
+	} while(timeout--);
 }
 
 static void siu_console_putchar(struct uart_port *port, int ch)
drivers/serial/samsung.c +3 -3
@@ -139,7 +139,7 @@ static void s3c24xx_serial_stop_tx(struc
 	if (tx_enabled(port)) {
 		disable_irq(TX_IRQ(port));
 		tx_enabled(port) = 0;
-		if (port->flags & UPF_CONS_FLOW)
+		if (uart_has_hw_flow_control(port))
 			s3c24xx_serial_rx_enable(port);
 	}
 }
@@ -147,7 +147,7 @@ static void s3c24xx_serial_stop_tx(struc
 static void s3c24xx_serial_start_tx(struct uart_port *port)
 {
 	if (!tx_enabled(port)) {
-		if (port->flags & UPF_CONS_FLOW)
+		if (uart_has_hw_flow_control(port))
 			s3c24xx_serial_rx_disable(port);
 
 		enable_irq(TX_IRQ(port));
@@ -216,7 +216,7 @@ s3c24xx_serial_rx_chars(int irq, void *d
 		uerstat = rd_regl(port, S3C2410_UERSTAT);
 		ch = rd_regb(port, S3C2410_URXH);
 
-		if (port->flags & UPF_CONS_FLOW) {
+		if (uart_has_hw_flow_control(port)) {
 			int txe = s3c24xx_serial_txempty_nofifo(port);
 
 			if (rx_enabled(port)) {
Signature · 1 line
Aristeu