serial: imx: support RS-485 Rx disable on Tx
Subsystems (2)
PATCH 1/1 serial: imx: support RS-485 Rx disable on Tx
Some RS-232 to RS-485 transceivers require Rx to be disabled on Tx to avoid echo of Tx data into the Rx buffer. Specifically, the XR3160E RS-232/RS-485/RS-422 transceiver behaves this way.
This commit disables Rx on active Tx when SER_RS485_ENABLED is active and SER_RS485_RX_DURING_TX is disabled.
Note that this is a change in behavior of the driver. Until now SER_RS485_RX_DURING_TX was enabled unconditionally even when disabled in the TIOCSRS485 ioctl serial_rs485 flags field.
--- drivers/tty/serial/imx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/imx.c +4 -1
@@ -361,6 +361,8 @@ static void imx_stop_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp |=UCR2_RXEN ;writel (temp, port->membase +UCR2 ); temp =readl (port->membase +UCR4 );
@@ -568,6 +570,8 @@ static void imx_start_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp &= ~UCR2_RXEN ;writel (temp, port->membase +UCR2 );/* enable transmitter and shifter empty irq */
@@ -1614,7 +1618,6 @@ static int imx_rs485_config(struct uart_port *port,/* unimplemented */ rs485conf->delay_rts_before_send =0 ; rs485conf->delay_rts_after_send =0 ; - rs485conf->flags |=SER_RS485_RX_DURING_TX ;/* RTS is required to control the transmitter */ if (!sport->have_rtscts)
Signature · 1 line
2.7.0
PATCH 1/1 serial: imx: support RS-485 Rx disable on Tx
Hello Baruch,
Quoted 8 lines · Baruch Siach
Some RS-232 to RS-485 transceivers require Rx to be disabled on Tx to avoid echo of Tx data into the Rx buffer. Specifically, the XR3160E RS-232/RS-485/RS-422 transceiver behaves this way.
This commit disables Rx on active Tx when
SER_RS485_ENABLEDis active andSER_RS485_RX_DURING_TXis disabled.Note that this is a change in behavior of the driver. Until now
But this change is a good one (assuming it does what it advertises :-). Userspace got informed before that SER_RS485_RX_DURING_TX is enabled, so this is not an incompatible change.
Best regards
Uwe
Quoted 23 lines
SER_RS485_RX_DURING_TXwas enabled unconditionally even when disabled in the TIOCSRS485 ioctlserial_rs485flags field.Cc Uwe Kleine-K?nig <[email protected]>Signed-off-by Baruch Siach <[email protected]>--- drivers/tty/serial/imx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/tty/serial/imx.c +2
-0@@ -361,6 +361,8 @@ static void imx_stop_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp |=UCR2_RXEN ;writel (temp, port->membase +UCR2 ); temp =readl (port->membase +UCR4 );
drivers/tty/serial/imx.c static void imx_start_tx(struct uart_port *port) · line 575
Quoted 6 lines
drivers/tty/serial/imx.c +2
-0@@ -568,6 +570,8 @@ static void imx_start_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp &= ~UCR2_RXEN ;writel (temp, port->membase +UCR2 );
Can this happen:
- SER_RS485_RX_DURING_TX is off
- thread A starts sending (and so disables RX)
- thread B sets SER_RS485_RX_DURING_TX
- thread A finishes sending, and doesn't restore RXEN.
?
Even if this cannot happen it might be more robust to restore RXEN unconditionally in imx_stop_tx?!
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/1 serial: imx: support RS-485 Rx disable on Tx
Hi Uwe,
Thanks for your prompt response.
Quoted 5 lines · Uwe Kleine-K?nig
Quoted 4 lines · Baruch Siach
Some RS-232 to RS-485 transceivers require Rx to be disabled on Tx to avoid echo of Tx data into the Rx buffer. Specifically, the XR3160E RS-232/RS-485/RS-422 transceiver behaves this way.
Quoted 8 lines
Quoted 4 lines
This commit disables Rx on active Tx when
SER_RS485_ENABLEDis active andSER_RS485_RX_DURING_TXis disabled.Note that this is a change in behavior of the driver. Until now
But this change is a good one (assuming it does what it advertises :-). Userspace got informed before that
SER_RS485_RX_DURING_TXis enabled, so this is not an incompatible change.
I thought it is a good idea to mention this fact in the commit log anyway. It is not hard to imagine broken userspace being affected by this change.
Quoted 37 lines
Quoted 23 lines
SER_RS485_RX_DURING_TXwas enabled unconditionally even when disabled in the TIOCSRS485 ioctlserial_rs485flags field.Cc Uwe Kleine-K?nig <[email protected]>Signed-off-by Baruch Siach <[email protected]>--- drivers/tty/serial/imx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/tty/serial/imx.c +2
-0@@ -361,6 +361,8 @@ static void imx_stop_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp |=UCR2_RXEN ;writel (temp, port->membase +UCR2 ); temp =readl (port->membase +UCR4 );drivers/tty/serial/imx.c static void imx_start_tx(struct uart_port *port) · line 575
Quoted 6 lines
drivers/tty/serial/imx.c +2
-0@@ -568,6 +570,8 @@ static void imx_start_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp &= ~UCR2_RXEN ;writel (temp, port->membase +UCR2 );Can this happen:
-
SER_RS485_RX_DURING_TXis off
- thread A starts sending (and so disables RX)
- thread B setsSER_RS485_RX_DURING_TX
- thread A finishes sending, and doesn't restore RXEN.
Quoted 4 lines
?
Even if this cannot happen it might be more robust to restore RXEN unconditionally in
imx_stop_tx?!
Sounds like a good idea. But if I take your comment to its logical conclusion, thread B might just disable SER_RS485_ENABLED entirely. Would it make sense to restore RXEN outside the 'if (port->rs485.flags & SER_RS485_ENABLED)' block? Or maybe we should just set RXEN in imx_rs485_config() when SER_RS485_RX_DURING_TX is enabled?
baruch
Signature · 3 lines
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -PATCH 1/1 serial: imx: support RS-485 Rx disable on Tx
Hello Baruch,
Quoted 59 lines · Baruch Siach
Thanks for your prompt response.
Quoted 5 lines · Uwe Kleine-K?nig
Quoted 4 lines · Baruch Siach
Some RS-232 to RS-485 transceivers require Rx to be disabled on Tx to avoid echo of Tx data into the Rx buffer. Specifically, the XR3160E RS-232/RS-485/RS-422 transceiver behaves this way.
Quoted 8 lines
Quoted 4 lines
This commit disables Rx on active Tx when
SER_RS485_ENABLEDis active andSER_RS485_RX_DURING_TXis disabled.Note that this is a change in behavior of the driver. Until now
But this change is a good one (assuming it does what it advertises :-). Userspace got informed before that
SER_RS485_RX_DURING_TXis enabled, so this is not an incompatible change.I thought it is a good idea to mention this fact in the commit log anyway. It is not hard to imagine broken userspace being affected by this change.
Quoted 39 lines
Quoted 23 lines
SER_RS485_RX_DURING_TXwas enabled unconditionally even when disabled in the TIOCSRS485 ioctlserial_rs485flags field.Cc Uwe Kleine-K?nig <[email protected]>Signed-off-by Baruch Siach <[email protected]>--- drivers/tty/serial/imx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/tty/serial/imx.c +2
-0@@ -361,6 +361,8 @@ static void imx_stop_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp |=UCR2_RXEN ;writel (temp, port->membase +UCR2 ); temp =readl (port->membase +UCR4 );drivers/tty/serial/imx.c static void imx_start_tx(struct uart_port *port) · line 575
Quoted 6 lines
drivers/tty/serial/imx.c +2
-0@@ -568,6 +570,8 @@ static void imx_start_tx(struct uart_port *port)imx_port_rts_inactive (sport, &temp); else imx_port_rts_active(sport, &temp); +if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) + temp &= ~UCR2_RXEN ;writel (temp, port->membase +UCR2 );Can this happen:
-
SER_RS485_RX_DURING_TXis off
- thread A starts sending (and so disables RX)
- thread B setsSER_RS485_RX_DURING_TX
- thread A finishes sending, and doesn't restore RXEN.?
Quoted 8 lines
Quoted 2 lines
Even if this cannot happen it might be more robust to restore RXEN unconditionally in
imx_stop_tx?!Sounds like a good idea. But if I take your comment to its logical conclusion, thread B might just disable
SER_RS485_ENABLEDentirely. Would it make sense to restore RXEN outside the 'if (port->rs485.flags&SER_RS485_ENABLED)' block? Or maybe we should just set RXEN inimx_rs485_config()whenSER_RS485_RX_DURING_TXis enabled?
The latter sounds like the right thing to do.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |