]>
Commit | Line | Data |
---|---|---|
1fd55d47 GKH |
1 | From f3040983132bf3477acd45d2452a906e67c2fec9 Mon Sep 17 00:00:00 2001 |
2 | From: Razvan Stefanescu <razvan.stefanescu@microchip.com> | |
3 | Date: Tue, 19 Mar 2019 15:20:34 +0200 | |
4 | Subject: tty/serial: atmel: Add is_half_duplex helper | |
5 | ||
6 | From: Razvan Stefanescu <razvan.stefanescu@microchip.com> | |
7 | ||
8 | commit f3040983132bf3477acd45d2452a906e67c2fec9 upstream. | |
9 | ||
10 | Use a helper function to check that a port needs to use half duplex | |
11 | communication, replacing several occurrences of multi-line bit checking. | |
12 | ||
13 | Fixes: b389f173aaa1 ("tty/serial: atmel: RS485 half duplex w/DMA: enable RX after TX is done") | |
14 | Cc: stable <stable@vger.kernel.org> | |
15 | Signed-off-by: Razvan Stefanescu <razvan.stefanescu@microchip.com> | |
16 | Acked-by: Richard Genoud <richard.genoud@gmail.com> | |
17 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
18 | ||
19 | ||
20 | --- | |
21 | drivers/tty/serial/atmel_serial.c | 19 +++++++++++-------- | |
22 | 1 file changed, 11 insertions(+), 8 deletions(-) | |
23 | ||
24 | --- a/drivers/tty/serial/atmel_serial.c | |
25 | +++ b/drivers/tty/serial/atmel_serial.c | |
26 | @@ -238,6 +238,12 @@ static inline void atmel_uart_write_char | |
27 | __raw_writeb(value, port->membase + ATMEL_US_THR); | |
28 | } | |
29 | ||
30 | +static inline int atmel_uart_is_half_duplex(struct uart_port *port) | |
31 | +{ | |
32 | + return (port->rs485.flags & SER_RS485_ENABLED) && | |
33 | + !(port->rs485.flags & SER_RS485_RX_DURING_TX); | |
34 | +} | |
35 | + | |
36 | #ifdef CONFIG_SERIAL_ATMEL_PDC | |
37 | static bool atmel_use_pdc_rx(struct uart_port *port) | |
38 | { | |
39 | @@ -489,9 +495,9 @@ static void atmel_stop_tx(struct uart_po | |
40 | /* Disable interrupts */ | |
41 | atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); | |
42 | ||
43 | - if ((port->rs485.flags & SER_RS485_ENABLED) && | |
44 | - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) | |
45 | + if (atmel_uart_is_half_duplex(port)) | |
46 | atmel_start_rx(port); | |
47 | + | |
48 | } | |
49 | ||
50 | /* | |
51 | @@ -508,8 +514,7 @@ static void atmel_start_tx(struct uart_p | |
52 | return; | |
53 | ||
54 | if (atmel_use_pdc_tx(port) || atmel_use_dma_tx(port)) | |
55 | - if ((port->rs485.flags & SER_RS485_ENABLED) && | |
56 | - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) | |
57 | + if (atmel_uart_is_half_duplex(port)) | |
58 | atmel_stop_rx(port); | |
59 | ||
60 | if (atmel_use_pdc_tx(port)) | |
61 | @@ -806,8 +811,7 @@ static void atmel_complete_tx_dma(void * | |
62 | */ | |
63 | if (!uart_circ_empty(xmit)) | |
64 | atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); | |
65 | - else if ((port->rs485.flags & SER_RS485_ENABLED) && | |
66 | - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { | |
67 | + else if (atmel_uart_is_half_duplex(port)) { | |
68 | /* DMA done, stop TX, start RX for RS485 */ | |
69 | atmel_start_rx(port); | |
70 | } | |
71 | @@ -1383,8 +1387,7 @@ static void atmel_tx_pdc(struct uart_por | |
72 | atmel_uart_writel(port, ATMEL_US_IER, | |
73 | atmel_port->tx_done_mask); | |
74 | } else { | |
75 | - if ((port->rs485.flags & SER_RS485_ENABLED) && | |
76 | - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { | |
77 | + if (atmel_uart_is_half_duplex(port)) { | |
78 | /* DMA done, stop TX, start RX for RS485 */ | |
79 | atmel_start_rx(port); | |
80 | } |