Skip to content

Commit 565e7c9

Browse files
passgatgregkh
authored andcommitted
serial: omap: fix rs485 half-duplex filtering
[ Upstream commit e2a5e84 ] Data received during half-duplex transmission must be filtered. If the target device responds quickly, emptying the FIFO at the end of the transmission can erase not only the echo characters but also part of the response message. By keeping the receive interrupt enabled even during transmission, it allows you to filter each echo character and only in a number equal to those transmitted. The issue was generated by a target device that started responding 240us later having received a request in communication at 115200bps. Sometimes, some messages received by the target were missing some of the first bytes. Fixes: 3a13884 ("tty/serial: omap: empty the RX FIFO at the end of half-duplex TX") Signed-off-by: Dario Binacchi <dariobin@libero.it> Link: https://lore.kernel.org/r/20210418094705.27014-1-dariobin@libero.it Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9c3e2ad commit 565e7c9

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

‎drivers/tty/serial/omap-serial.c‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ struct uart_omap_port {
159159
u32 calc_latency;
160160
struct work_struct qos_work;
161161
bool is_suspending;
162+
163+
unsigned int rs485_tx_filter_count;
162164
};
163165

164166
#define to_uart_omap_port(p) ((container_of((p), struct uart_omap_port, port)))
@@ -329,19 +331,6 @@ static void serial_omap_stop_tx(struct uart_port *port)
329331
serial_out(up, UART_IER, up->ier);
330332
}
331333

332-
if ((port->rs485.flags & SER_RS485_ENABLED) &&
333-
!(port->rs485.flags & SER_RS485_RX_DURING_TX)) {
334-
/*
335-
* Empty the RX FIFO, we are not interested in anything
336-
* received during the half-duplex transmission.
337-
*/
338-
serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_RCVR);
339-
/* Re-enable RX interrupts */
340-
up->ier |= UART_IER_RLSI | UART_IER_RDI;
341-
up->port.read_status_mask |= UART_LSR_DR;
342-
serial_out(up, UART_IER, up->ier);
343-
}
344-
345334
pm_runtime_mark_last_busy(up->dev);
346335
pm_runtime_put_autosuspend(up->dev);
347336
}
@@ -367,6 +356,10 @@ static void transmit_chars(struct uart_omap_port *up, unsigned int lsr)
367356
serial_out(up, UART_TX, up->port.x_char);
368357
up->port.icount.tx++;
369358
up->port.x_char = 0;
359+
if ((up->port.rs485.flags & SER_RS485_ENABLED) &&
360+
!(up->port.rs485.flags & SER_RS485_RX_DURING_TX))
361+
up->rs485_tx_filter_count++;
362+
370363
return;
371364
}
372365
if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
@@ -378,6 +371,10 @@ static void transmit_chars(struct uart_omap_port *up, unsigned int lsr)
378371
serial_out(up, UART_TX, xmit->buf[xmit->tail]);
379372
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
380373
up->port.icount.tx++;
374+
if ((up->port.rs485.flags & SER_RS485_ENABLED) &&
375+
!(up->port.rs485.flags & SER_RS485_RX_DURING_TX))
376+
up->rs485_tx_filter_count++;
377+
381378
if (uart_circ_empty(xmit))
382379
break;
383380
} while (--count > 0);
@@ -421,7 +418,7 @@ static void serial_omap_start_tx(struct uart_port *port)
421418

422419
if ((port->rs485.flags & SER_RS485_ENABLED) &&
423420
!(port->rs485.flags & SER_RS485_RX_DURING_TX))
424-
serial_omap_stop_rx(port);
421+
up->rs485_tx_filter_count = 0;
425422

426423
serial_omap_enable_ier_thri(up);
427424
pm_runtime_mark_last_busy(up->dev);
@@ -492,8 +489,13 @@ static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr)
492489
* Read one data character out to avoid stalling the receiver according
493490
* to the table 23-246 of the omap4 TRM.
494491
*/
495-
if (likely(lsr & UART_LSR_DR))
492+
if (likely(lsr & UART_LSR_DR)) {
496493
serial_in(up, UART_RX);
494+
if ((up->port.rs485.flags & SER_RS485_ENABLED) &&
495+
!(up->port.rs485.flags & SER_RS485_RX_DURING_TX) &&
496+
up->rs485_tx_filter_count)
497+
up->rs485_tx_filter_count--;
498+
}
497499

498500
up->port.icount.rx++;
499501
flag = TTY_NORMAL;
@@ -544,6 +546,13 @@ static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr)
544546
return;
545547

546548
ch = serial_in(up, UART_RX);
549+
if ((up->port.rs485.flags & SER_RS485_ENABLED) &&
550+
!(up->port.rs485.flags & SER_RS485_RX_DURING_TX) &&
551+
up->rs485_tx_filter_count) {
552+
up->rs485_tx_filter_count--;
553+
return;
554+
}
555+
547556
flag = TTY_NORMAL;
548557
up->port.icount.rx++;
549558

0 commit comments

Comments
 (0)