Skip to content

Commit 7df5081

Browse files
Marek Vasutgregkh
authored andcommitted
serial: stm32: Add RS485 RTS GPIO control
While the STM32 does support RS485 drive-enable control within the UART IP itself, some systems have the drive-enable line connected to a pin which cannot be pinmuxed as RTS. Add support for toggling the RTS GPIO line using the modem control GPIOs to provide at least some sort of emulation. Signed-off-by: Marek Vasut <[email protected]> Cc: Alexandre Torgue <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Manivannan Sadhasivam <[email protected]> Cc: Fabrice Gasnier <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cc81696 commit 7df5081

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/tty/serial/stm32-usart.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ static int stm32_config_rs485(struct uart_port *port,
129129
if (rs485conf->flags & SER_RS485_RTS_ON_SEND) {
130130
cr3 &= ~USART_CR3_DEP;
131131
rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND;
132+
mctrl_gpio_set(stm32_port->gpios,
133+
stm32_port->port.mctrl & ~TIOCM_RTS);
132134
} else {
133135
cr3 |= USART_CR3_DEP;
134136
rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
137+
mctrl_gpio_set(stm32_port->gpios,
138+
stm32_port->port.mctrl | TIOCM_RTS);
135139
}
136140

137141
writel_relaxed(cr3, port->membase + ofs->cr3);
@@ -847,9 +851,13 @@ static void stm32_set_termios(struct uart_port *port, struct ktermios *termios,
847851
if (rs485conf->flags & SER_RS485_RTS_ON_SEND) {
848852
cr3 &= ~USART_CR3_DEP;
849853
rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND;
854+
mctrl_gpio_set(stm32_port->gpios,
855+
stm32_port->port.mctrl & ~TIOCM_RTS);
850856
} else {
851857
cr3 |= USART_CR3_DEP;
852858
rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
859+
mctrl_gpio_set(stm32_port->gpios,
860+
stm32_port->port.mctrl | TIOCM_RTS);
853861
}
854862

855863
} else {

0 commit comments

Comments
 (0)