public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Russell King" <linux@armlinux.org.uk>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Lino Sanfilippo" <LinoSanfilippo@gmx.de>,
	m.brock@vanmierlo.com, "David Laight" <David.Laight@aculab.com>
Subject: Re: [PATCH] serial: Revert RS485 polarity change on UART open
Date: Wed, 29 Jun 2022 19:01:52 +0200	[thread overview]
Message-ID: <20220629170152.GA24851@wunner.de> (raw)
In-Reply-To: <383f5d66d6828a5f09f5705f6ff98e3727ecfdf2.camel@ew.tq-group.com>

On Mon, Jun 27, 2022 at 10:40:36AM +0200, Matthias Schiffer wrote:
> On Tue, 2022-03-29 at 12:39 +0200, Matthias Schiffer wrote:
> > On Tue, 2022-03-29 at 12:03 +0200, Lukas Wunner wrote:
> > > On Tue, Mar 29, 2022 at 10:50:50AM +0200, Matthias Schiffer wrote:
> > > > While the change of the RS485 polarity in
> > > > commit d3b3404df318 ("serial: Fix incorrect rs485 polarity on uart
> > > > open")
> > > > might have made sense based on the original intention of the
> > > > rs485-rts-active-low flag (*), this is not how it is implemented in
> > > > various drivers:
> > > [...]
> > > > [(*) My understanding of the mentioned commit's description is that
> > > > rs485-rts-active-low should have referred to the electical signal
> > > > level
> > > > of the RTS pin, rather than the logical RTS state as understood by
> > > > the
> > > > UART controller.]
> 
> do you know if there has been any progress on this issue? I see that
> there has been quite a bit of activity in the RS485 code in linux-next, 
> but I didn't have time to check if that has any effect on the polarity
> issue so far.

No, the issue has not been resolved yet but at least I have inspected
all drivers now and compiled a list of their behavior:

          8250_bcm2835aux: identity (RTS in software)
          8250_dwlib:      identity (RTS in hardware, DE active high after POR)
                           inverse  (RTS in software em485)
          8250_exar:       identity (RTS in hardware)
          8250_fintek:     inverse  (RTS in hardware)
          8250_lpc18xx:    identity (RTS in hardware)
          8250_of:         inverse  (RTS in software em485)
                                    [ns8250, ns16550, lpc3220, da830, wpcm450]
          8250_omap:       inverse  (RTS in software em485)
          8250_pci:        identity (RTS in hardware)
          amba-pl011:      identity (RTS in software)
          ar933x_uart:     identity (RTS as gpio)
          atmel_serial:    identity (RTS in hardware, only high supported)
          fsl_lpuart:      inverse  (RTS in hardware)
          imx:             identity (RTS as gpio or CTS in software)
          max310x:         identity (RTS in hardware)
          mcf:             identity (RTS in hardware)
          omap-serial:     identity (RTS as gpio)
          sc16is7xx:       inverse  (RTS in hardware)
          stm32-usart:     identity (RTS in hardware)
                           identity (RTS as gpio)

Where "identity" means that SER_RS485_RTS_ON_SEND results in "high"
voltage level and "inverse" means it results in "low" voltage level.

Unless I've made any mistakes here, it looks like the majority of
drivers use "identity".  The only ones using inverse polarity are
8250-compatible UARTs using em485 software emulation (with the
exception of bcm2835aux), plus three UART drivers which use
hardware-driven RTS.

When you reported the issue, you claimed that i.MX, OMAP and STM32
drivers use inverse polarity.  I was only able to confirm that for
OMAP (if 8250_omap.c is used, not the older omap-serial.c).

When you refer to i.MX, I suppose you're referring to fsl_lpuart.c
(which uses hardware-controlled RTS assertion on newer i.MX SoCs),
not imx.c, right?  The latter offers two options to drive an RS-485
transceiver, either through CTS or through an mctrl_gpio.
imx_uart_rts_active() clears the CTS bit in the UCR2 register.
According to page 4679 of iMX53RM.pdf, that means "high" voltage level,
hence "identity".  And if an mctrl_gpio is used, mctrl_gpio_set()
sets the GPIO to "active", which likewise means "high" voltage level
unless you've specified the GPIO as active-low in the devicetree:
https://www.nxp.com/docs/en/reference-manual/iMX53RM.pdf

As for stm32-usart.c, the driver offers either hardware-controlled
RTS assertion or mctrl_gpio.  The hardware-controlled variant clears
the DEP bit in the USART_CR3 register if SER_RS485_RTS_ON_SEND is set.
According to page 1392 of the STM32 documentation this means that
"DE signal is active high", so it seems to me that this driver uses
"identity and not "inverse" as claimed:
https://www.st.com/resource/en/reference_manual/rm0351-stm32l47xxx-stm32l48xxx-stm32l49xxx-and-stm32l4axxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

Anyway, I'll try to come up with a fix for the affected em485 drivers
by next week.  The "inverse" drivers with hardware-controlled RTS
should not be affected by d3b3404df318 (unless I'm missing something).

Thanks!

Lukas

      reply	other threads:[~2022-06-29 17:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  8:50 [PATCH] serial: Revert RS485 polarity change on UART open Matthias Schiffer
2022-03-29 10:03 ` Lukas Wunner
2022-03-29 10:39   ` Matthias Schiffer
2022-03-29 12:55     ` David Laight
2022-03-29 13:02       ` Matthias Schiffer
2022-03-29 13:19         ` David Laight
2022-03-29 13:36           ` (EXT) " Matthias Schiffer
2022-05-11 10:22           ` m.brock
2022-06-27  8:40     ` Matthias Schiffer
2022-06-29 17:01       ` Lukas Wunner [this message]

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=20220629170152.GA24851@wunner.de \
    --to=lukas@wunner.de \
    --cc=David.Laight@aculab.com \
    --cc=LinoSanfilippo@gmx.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=m.brock@vanmierlo.com \
    --cc=matthias.schiffer@ew.tq-group.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox