tty/serial: atmel: RS485 half duplex w/DMA: enable RX after TX is done
Subsystems (4)
PATCH 1/1 tty/serial: atmel: RS485 half duplex w/DMA: enable RX after TX is done
When using RS485 in half duplex, RX should be enabled when TX is finished, and stopped when TX starts.
Before commit 0058f0871efe7b01c6 ("tty/serial: atmel: fix RS485 half duplex with DMA"), RX was not disabled in atmel_start_tx() if the DMA was used. So, collisions could happened.
But disabling RX in atmel_start_tx() uncovered another bug:
RX was enabled again in the wrong place (in atmel_tx_dma) instead of being enabled when TX is finished (in atmel_complete_tx_dma), so the transmission simply stopped.
This bug was not triggered before commit 0058f0871efe7b01c6 ("tty/serial: atmel: fix RS485 half duplex with DMA") because RX was never disabled before.
Moving atmel_start_rx() in atmel_complete_tx_dma() corrects the problem.
--- drivers/tty/serial/atmel_serial.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/tty/serial/atmel_serial.c +5 -6
@@ -798,6 +798,11 @@ static void atmel_complete_tx_dma(void *arg)*/ if (!uart_circ_empty (xmit))atmel_tasklet_schedule (atmel_port, &atmel_port->tasklet_tx); +else if ((port->rs485.flags &SER_RS485_ENABLED ) && + !(port->rs485.flags &SER_RS485_RX_DURING_TX )) { +/* DMA done, stop TX, start RX for RS485 */ +atmel_start_rx (port); + }spin_unlock_irqrestore (&port->lock, flags); }
@@ -900,12 +905,6 @@ static void atmel_tx_dma(struct uart_port *port) desc->callback = atmel_complete_tx_dma; desc->callback_param = atmel_port; atmel_port->cookie_tx =dmaengine_submit (desc); - - }else { -if (port->rs485.flags &SER_RS485_ENABLED ) { -/* DMA done, stop TX, start RX for RS485 */ -atmel_start_rx (port); - } }if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )
Quoted 16 lines · Richard Genoud
When using RS485 in half duplex, RX should be enabled when TX is finished, and stopped when TX starts.
Before commit
0058f0871efe7b01c6("tty/serial: atmel: fix RS485 half duplex with DMA"), RX was not disabled inatmel_start_tx()if the DMA was used. So, collisions could happened.But disabling RX in
atmel_start_tx()uncovered another bug:
RX was enabled again in the wrong place (inatmel_tx_dma) instead of being enabled when TX is finished (inatmel_complete_tx_dma), so the transmission simply stopped.This bug was not triggered before commit
0058f0871efe7b01c6("tty/serial: atmel: fix RS485 half duplex with DMA") because RX was never disabled before.
Quoted 6 lines
Moving
atmel_start_rx()inatmel_complete_tx_dma()corrects the problem.Reported-by Gil Weber <[email protected]>Tested-by Gil Weber <[email protected]>Signed-off-by Richard Genoud <[email protected]>
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
2017-01-02 12:53 GMT+01:00 Alexandre Belloni
<[email protected]>:
Quoted 17 lines · Richard Genoud
Quoted 16 lines
When using RS485 in half duplex, RX should be enabled when TX is finished, and stopped when TX starts.
Before commit
0058f0871efe7b01c6("tty/serial: atmel: fix RS485 half duplex with DMA"), RX was not disabled inatmel_start_tx()if the DMA was used. So, collisions could happened.But disabling RX in
atmel_start_tx()uncovered another bug:
RX was enabled again in the wrong place (inatmel_tx_dma) instead of being enabled when TX is finished (inatmel_complete_tx_dma), so the transmission simply stopped.This bug was not triggered before commit
0058f0871efe7b01c6("tty/serial: atmel: fix RS485 half duplex with DMA") because RX was never disabled before.
Quoted 9 lines
Quoted 6 lines
Moving
atmel_start_rx()inatmel_complete_tx_dma()corrects the problem.Reported-by Gil Weber <[email protected]>Tested-by Gil Weber <[email protected]>Signed-off-by Richard Genoud <[email protected]>
Greg, could you take this patch in your tree ?
Greg KH
maintainerQuoted 21 lines · Richard Genoud
2017-01-02 12:53 GMT+01:00 Alexandre Belloni
<[email protected]>:Quoted 19 lines · Richard Genoud
Quoted 18 lines
When using RS485 in half duplex, RX should be enabled when TX is finished, and stopped when TX starts.
Before commit
0058f0871efe7b01c6("tty/serial: atmel: fix RS485 half duplex with DMA"), RX was not disabled inatmel_start_tx()if the DMA was used. So, collisions could happened.But disabling RX in
atmel_start_tx()uncovered another bug:
RX was enabled again in the wrong place (inatmel_tx_dma) instead of being enabled when TX is finished (inatmel_complete_tx_dma), so the transmission simply stopped.This bug was not triggered before commit
0058f0871efe7b01c6("tty/serial: atmel: fix RS485 half duplex with DMA") because RX was never disabled before.Moving
atmel_start_rx()inatmel_complete_tx_dma()corrects the problem.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Reported-by Gil Weber <[email protected]>Tested-by Gil Weber <[email protected]>Signed-off-by Richard Genoud <[email protected]>Greg, could you take this patch in your tree ?
Yes, will do so, thanks.
greg k-h