All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Lukas Wunner <lukas@wunner.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Su Bao Cheng <baocheng.su@siemens.com>,
	baocheng_su@163.com, Jan Kiszka <jan.kiszka@siemens.com>,
	Chao Zeng <chao.zeng@siemens.com>,
	linux-serial@vger.kernel.org,
	Lino Sanfilippo <LinoSanfilippo@gmx.de>,
	Philipp Rosenberger <p.rosenberger@kunbus.com>,
	Rafael Gago Castano <rgc@hms.se>
Subject: Re: [PATCH] serial: Fix incorrect rs485 polarity on uart open
Date: Mon, 20 Dec 2021 07:28:00 +0100	[thread overview]
Message-ID: <8a10bea0-fb8a-c25a-6828-ab907b336d0b@kernel.org> (raw)
In-Reply-To: <9395767847833f2f3193c49cde38501eeb3b5669.1639821059.git.lukas@wunner.de>

On 18. 12. 21, 10:58, Lukas Wunner wrote:
> Commit a6845e1e1b78 ("serial: core: Consider rs485 settings to drive
> RTS") sought to deassert RTS when opening an rs485-enabled uart port.
> That way, the transceiver does not occupy the bus until it transmits
> data.
> 
> Unfortunately, the commit mixed up the logic and *asserted* RTS instead
> of *deasserting* it:
> 
> The commit amended uart_port_dtr_rts(), which raises DTR and RTS when
> opening an rs232 port.  "Raising" actually means lowering the signal
> that's coming out of the uart, because an rs232 transceiver not only
> changes a signal's voltage level, it also *inverts* the signal.  See
> the simplified schematic in the MAX232 datasheet for an example:
> https://www.ti.com/lit/ds/symlink/max232.pdf
> 
> So, to raise RTS on an rs232 port, TIOCM_RTS is *set* in port->mctrl
> and that results in the signal being driven low.
> 
> In contrast to rs232, the signal level for rs485 Transmit Enable is the
> identity, not the inversion:  If the transceiver expects a "high" RTS
> signal for Transmit Enable, the signal coming out of the uart must also
> be high, so TIOCM_RTS must be *cleared* in port->mctrl.
> 
> The commit did the exact opposite, but it's easy to see why given the
> confusing semantics of rs232 and rs485.  Fix it.
> 
> Fixes: a6845e1e1b78 ("serial: core: Consider rs485 settings to drive RTS")
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Cc: stable@vger.kernel.org # v4.14+
> Cc: Rafael Gago Castano <rgc@hms.se>

Rafael, can you ack/test this, please?

> Cc: Jan Kiszka <jan.kiszka@siemens.com>
> Cc: Su Bao Cheng <baocheng.su@siemens.com>
> ---
>   drivers/tty/serial/serial_core.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 29f4781..259f28e 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -162,7 +162,7 @@ static void uart_port_dtr_rts(struct uart_port *uport, int raise)
>   	int RTS_after_send = !!(uport->rs485.flags & SER_RS485_RTS_AFTER_SEND);
>   
>   	if (raise) {
> -		if (rs485_on && !RTS_after_send) {
> +		if (rs485_on && RTS_after_send) {
>   			uart_set_mctrl(uport, TIOCM_DTR);
>   			uart_clear_mctrl(uport, TIOCM_RTS);
>   		} else {
> @@ -171,7 +171,7 @@ static void uart_port_dtr_rts(struct uart_port *uport, int raise)
>   	} else {
>   		unsigned int clear = TIOCM_DTR;
>   
> -		clear |= (!rs485_on || !RTS_after_send) ? TIOCM_RTS : 0;
> +		clear |= (!rs485_on || RTS_after_send) ? TIOCM_RTS : 0;
>   		uart_clear_mctrl(uport, clear);
>   	}
>   }


-- 
js
suse labs

  reply	other threads:[~2021-12-20  6:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-18  9:58 [PATCH] serial: Fix incorrect rs485 polarity on uart open Lukas Wunner
2021-12-20  6:28 ` Jiri Slaby [this message]
2021-12-20  6:30   ` Jiri Slaby
2021-12-27 13:17     ` Lukas Wunner
2022-08-04 14:38 ` Roosen Henri
2022-08-04 15:52   ` Lukas Wunner
2022-08-04 16:11     ` Roosen Henri
2022-08-05  8:18       ` Lukas Wunner
     [not found]         ` <33b4b797-cd4a-436e-8e03-4bc5d7dd69ff.d000f9d8-ed3e-456c-b23a-5a86eac57608.c023ef82-f7f7-4a43-92f1-8642a4f822e1@emailsignatures365.codetwo.com>
     [not found]           ` <33b4b797-cd4a-436e-8e03-4bc5d7dd69ff.0668d69a-b7f6-4fc6-94cd-e3b904d4ce63.488ca449-4f1c-444b-8de0-1344d3aeb879@emailsignatures365.codetwo.com>
2022-08-05 11:20             ` Roosen Henri
2022-08-11  6:18               ` Lukas Wunner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8a10bea0-fb8a-c25a-6828-ab907b336d0b@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=LinoSanfilippo@gmx.de \
    --cc=baocheng.su@siemens.com \
    --cc=baocheng_su@163.com \
    --cc=chao.zeng@siemens.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jan.kiszka@siemens.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=p.rosenberger@kunbus.com \
    --cc=rgc@hms.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.