History

serial: 8250: Generalize rs485 software emulation

Commit e490c9144cfa ("tty: Add software emulated RS485 support for 8250") introduced support to use RTS as an rs485 Transmit Enable signal. So far the only drivers taking advantage of it are 8250_omap.c and 8250_of.c. We're about to make use of the feature in 8250_bcm2835aux.c as well. The bcm2835aux differs from omap chips by inverting the meaning of RTS in the MCR register. Moreover, omap achieves half-duplex mode by disabling the RX interrupt and clearing the RX FIFO when TX stops. The bcm2835aux requires disabling the receiver instead. Support these behavioral differences by generalizing the rs485 emulation: Introduce ->rs485_start_tx() and ->rs485_stop_tx() callbacks in struct uart_8250_port, provide generic implementations containing the existing code and use them as callbacks in 8250_omap.c and 8250_of.c. start_tx_rs485() is idempotent in that it recognizes whether RTS is already asserted. Achieve the same by introducing a tx_stopped flag in struct uart_8250_em485. This may even perform a little better on arches where memory access is faster than mmio access.

Lukas Wunner committed 6 years ago

Commit 058bc101 parent 41a70b76 files · +67 −31Browse files

Showing the changes to include/linux (1 of 6 files). Show all

Unified · Split

include/linux/serial_8250.h+3−0
@@ -81,6 +81,7 @@ struct uart_8250_em485 { · 80 unmodified lines
8181 struct hrtimer stop_tx_timer; /* "rs485 stop tx" timer */
8282 struct hrtimer *active_timer; /* pointer to active timer */
8383 struct uart_8250_port *port; /* for hrtimer callbacks */
84+ unsigned int tx_stopped:1; /* tx is currently stopped */
8485 };
8586
8687 /*
@@ -132,6 +133,8 @@ struct uart_8250_port { · 45 unmodified lines
132133 void (*dl_write)(struct uart_8250_port *, int);
133134
134135 struct uart_8250_em485 *em485;
136+ void (*rs485_start_tx)(struct uart_8250_port *);
137+ void (*rs485_stop_tx)(struct uart_8250_port *);
135138
136139 /* Serial port overrun backoff */
137140 struct delayed_work overrun_backoff;