[PATCH v1 04/31] serial: 8250_mxupci: enable auto RTS/CTS flow control

Crescent Hsieh posted 31 patches 1 day, 11 hours ago
[PATCH v1 04/31] serial: 8250_mxupci: enable auto RTS/CTS flow control
Posted by Crescent Hsieh 1 day, 11 hours ago
Implement a custom set_termios() to configure RTS/CTS hardware flow
control. When CRTSCTS is enabled in termios, the UART_MCR[5] AFE (Auto
Flow Control Enable) bit is set to allow automatic RTS/CTS signaling.

Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
 drivers/tty/serial/8250/8250_mxupci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_mxupci.c b/drivers/tty/serial/8250/8250_mxupci.c
index c4fa52de8962..54e50cd3f472 100644
--- a/drivers/tty/serial/8250/8250_mxupci.c
+++ b/drivers/tty/serial/8250/8250_mxupci.c
@@ -78,6 +78,26 @@ static unsigned short mxupci8250_get_nports(unsigned short device)
 	return FIELD_GET(0x00F0, device);
 }
 
+static void mxupci8250_set_termios(struct uart_port *port, struct ktermios *new,
+				   const struct ktermios *old)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	struct tty_struct *tty = port->state->port.tty;
+	unsigned int cflag = tty->termios.c_cflag;
+
+	serial8250_do_set_termios(port, new, old);
+
+	up->port.status &= ~(UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
+
+	up->mcr &= ~UART_MCR_AFE;
+
+	if (cflag & CRTSCTS) {
+		up->mcr |= (UART_MCR_AFE | UART_MCR_RTS);
+		up->port.status |= (UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
+	}
+	serial_out(up, UART_MCR, up->mcr);
+}
+
 static int mxupci8250_startup(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
@@ -152,6 +172,7 @@ static int mxupci8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
 	up.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
 	up.port.type = PORT_MU860;
 
+	up.port.set_termios = mxupci8250_set_termios;
 	up.port.startup = mxupci8250_startup;
 	up.port.shutdown = mxupci8250_shutdown;
 
-- 
2.45.2
Re: [PATCH v1 04/31] serial: 8250_mxupci: enable auto RTS/CTS flow control
Posted by Andy Shevchenko 1 day, 4 hours ago
On Sun, Nov 30, 2025 at 12:43 PM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> Implement a custom set_termios() to configure RTS/CTS hardware flow
> control. When CRTSCTS is enabled in termios, the UART_MCR[5] AFE (Auto
> Flow Control Enable) bit is set to allow automatic RTS/CTS signaling.

...

> +static void mxupci8250_set_termios(struct uart_port *port, struct ktermios *new,
> +                                  const struct ktermios *old)
> +{
> +       struct uart_8250_port *up = up_to_u8250p(port);
> +       struct tty_struct *tty = port->state->port.tty;
> +       unsigned int cflag = tty->termios.c_cflag;
> +
> +       serial8250_do_set_termios(port, new, old);
> +
> +       up->port.status &= ~(UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
> +
> +       up->mcr &= ~UART_MCR_AFE;
> +
> +       if (cflag & CRTSCTS) {
> +               up->mcr |= (UART_MCR_AFE | UART_MCR_RTS);
> +               up->port.status |= (UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
> +       }
> +       serial_out(up, UART_MCR, up->mcr);
> +}

Here I have a déjà vu feeling, i.e. some other drivers may also do the
same or very similar steps to enable it (8250_dw?). Can we create a
helper for all of them? And if this is the case, perhaps add it to
8250_pcilib.c?

-- 
With Best Regards,
Andy Shevchenko