Linux-Serial Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 0/2] Implement support for inverted serial TX/RX on i.MX
@ 2020-02-10 19:29 George Hilliard
  2020-02-10 19:29 ` [PATCH v2 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
  2020-02-10 19:29 ` [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
  0 siblings, 2 replies; 7+ messages in thread
From: George Hilliard @ 2020-02-10 19:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: George Hilliard, NXP Linux Team, linux-serial, devicetree, kernel

This peripheral has dedicated control bits that flip input/output
signals before handing them off to the OS.  This is useful on my
hardware because the UART is connected to an RS-422 transceiver with the
+/- pins hooked up backward.  Instead of a hack flipping all the bits
before sending them, the hardware can do it for free.

Functionally unchanged from v1, but the confidentiality notice has been
removed.  I also CC'd other lists that Uwe suggested.

George Hilliard (2):
  dt-bindings: serial: document fsl,inverted-tx and -rx options
  tty: imx serial: Implement support for reversing TX and RX polarity

 .../bindings/serial/fsl-imx-uart.txt          |  4 ++++
 drivers/tty/serial/imx.c                      | 22 +++++++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)

-- 
2.25.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options
  2020-02-10 19:29 [PATCH v2 0/2] Implement support for inverted serial TX/RX on i.MX George Hilliard
@ 2020-02-10 19:29 ` George Hilliard
  2020-02-10 19:29 ` [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
  1 sibling, 0 replies; 7+ messages in thread
From: George Hilliard @ 2020-02-10 19:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: George Hilliard, NXP Linux Team, linux-serial, devicetree, kernel

Add a description for the new fsl,inverted-tx and fsl,inverted-rx
options for the i.MX UART peripheral.

Signed-off-by: George Hilliard <ghilliard@kopismobile.com>
---
v1..v2: Removed confidentiality spam

 Documentation/devicetree/bindings/serial/fsl-imx-uart.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt b/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
index 35957cbf1571..c8d677f9491f 100644
--- a/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
+++ b/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
@@ -8,6 +8,10 @@ Required properties:
 Optional properties:
 - fsl,dte-mode : Indicate the uart works in DTE mode. The uart works
                   in DCE mode by default.
+- fsl,inverted-tx , fsl,inverted-rx : Indicate that the hardware attached
+  to the peripheral inverts the signal transmitted or received,
+  respectively, and that the peripheral should invert its output/input
+  using the INVT/INVR registers.
 - rs485-rts-delay, rs485-rts-active-low, rs485-rx-during-tx,
   linux,rs485-enabled-at-boot-time: see rs485.txt. Note that for RS485
   you must enable either the "uart-has-rtscts" or the "rts-gpios"
-- 
2.25.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
  2020-02-10 19:29 [PATCH v2 0/2] Implement support for inverted serial TX/RX on i.MX George Hilliard
  2020-02-10 19:29 ` [PATCH v2 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
@ 2020-02-10 19:29 ` George Hilliard
  2020-02-10 20:50   ` Uwe Kleine-König
  1 sibling, 1 reply; 7+ messages in thread
From: George Hilliard @ 2020-02-10 19:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: George Hilliard, NXP Linux Team, linux-serial, devicetree, kernel

The peripheral has support for inverting its input and/or output
signals.  This is useful if the hardware flips polarity of the
peripheral's signal, such as swapped +/- pins on an RS-422 transceiver,
or an inverting level shifter.  Add support for these control registers
via the device tree binding.

Signed-off-by: George Hilliard <ghilliard@kopismobile.com>
---
v1..v2: removed confidentiality spam

 drivers/tty/serial/imx.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 0c6c63166250..467e78794997 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -195,6 +195,8 @@ struct imx_port {
 	unsigned int		have_rtscts:1;
 	unsigned int		have_rtsgpio:1;
 	unsigned int		dte_mode:1;
+	unsigned int		inverted_tx:1;
+	unsigned int		inverted_rx:1;
 	struct clk		*clk_ipg;
 	struct clk		*clk_per;
 	const struct imx_uart_data *devdata;
@@ -1335,7 +1337,7 @@ static int imx_uart_startup(struct uart_port *port)
 	int retval, i;
 	unsigned long flags;
 	int dma_is_inited = 0;
-	u32 ucr1, ucr2, ucr4;
+	u32 ucr1, ucr2, ucr3, ucr4;
 
 	retval = clk_prepare_enable(sport->clk_per);
 	if (retval)
@@ -1390,6 +1392,8 @@ static int imx_uart_startup(struct uart_port *port)
 	ucr4 = imx_uart_readl(sport, UCR4) & ~UCR4_OREN;
 	if (!sport->dma_is_enabled)
 		ucr4 |= UCR4_OREN;
+	if (sport->inverted_rx)
+		ucr4 |= UCR4_INVR;
 	imx_uart_writel(sport, ucr4, UCR4);
 
 	ucr2 = imx_uart_readl(sport, UCR2) & ~UCR2_ATEN;
@@ -1404,19 +1408,17 @@ static int imx_uart_startup(struct uart_port *port)
 		ucr2 &= ~UCR2_RTSEN;
 	imx_uart_writel(sport, ucr2, UCR2);
 
+	ucr3 = imx_uart_readl(sport, UCR3);
+	if (sport->inverted_tx)
+		ucr3 |= UCR3_INVT;
 	if (!imx_uart_is_imx1(sport)) {
-		u32 ucr3;
-
-		ucr3 = imx_uart_readl(sport, UCR3);
-
 		ucr3 |= UCR3_DTRDEN | UCR3_RI | UCR3_DCD;
 
 		if (sport->dte_mode)
 			/* disable broken interrupts */
 			ucr3 &= ~(UCR3_RI | UCR3_DCD);
-
-		imx_uart_writel(sport, ucr3, UCR3);
 	}
+	imx_uart_writel(sport, ucr3, UCR3);
 
 	/*
 	 * Enable modem status interrupts
@@ -2184,6 +2186,12 @@ static int imx_uart_probe_dt(struct imx_port *sport,
 	if (of_get_property(np, "rts-gpios", NULL))
 		sport->have_rtsgpio = 1;
 
+	if (of_get_property(np, "fsl,inverted-tx", NULL))
+		sport->inverted_tx = 1;
+
+	if (of_get_property(np, "fsl,inverted-rx", NULL))
+		sport->inverted_rx = 1;
+
 	return 0;
 }
 #else
-- 
2.25.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
  2020-02-10 19:29 ` [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
@ 2020-02-10 20:50   ` Uwe Kleine-König
  2020-02-10 23:03     ` George Hilliard
  0 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2020-02-10 20:50 UTC (permalink / raw)
  To: George Hilliard
  Cc: Greg Kroah-Hartman, kernel, devicetree, NXP Linux Team, linux-serial

Hello George,

On Mon, Feb 10, 2020 at 01:29:49PM -0600, George Hilliard wrote:
> @@ -1390,6 +1392,8 @@ static int imx_uart_startup(struct uart_port *port)
>  	ucr4 = imx_uart_readl(sport, UCR4) & ~UCR4_OREN;
>  	if (!sport->dma_is_enabled)
>  		ucr4 |= UCR4_OREN;
> +	if (sport->inverted_rx)
> +		ucr4 |= UCR4_INVR;

You fail to clear this bit if .inverted_rx is false.

>  	imx_uart_writel(sport, ucr4, UCR4);
>  
>  	ucr2 = imx_uart_readl(sport, UCR2) & ~UCR2_ATEN;
> @@ -1404,19 +1408,17 @@ static int imx_uart_startup(struct uart_port *port)
>  		ucr2 &= ~UCR2_RTSEN;
>  	imx_uart_writel(sport, ucr2, UCR2);
>  
> +	ucr3 = imx_uart_readl(sport, UCR3);
> +	if (sport->inverted_tx)
> +		ucr3 |= UCR3_INVT;

ditto.

Also I think setting this bit here is a bit late because UCR2_TXEN was
already set so changing UCR3_INVT probably results in a spike?!

>  	if (!imx_uart_is_imx1(sport)) {
> -		u32 ucr3;
> -
> -		ucr3 = imx_uart_readl(sport, UCR3);
> [...]

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
  2020-02-10 20:50   ` Uwe Kleine-König
@ 2020-02-10 23:03     ` George Hilliard
  2020-02-11  7:38       ` Uwe Kleine-König
  0 siblings, 1 reply; 7+ messages in thread
From: George Hilliard @ 2020-02-10 23:03 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Greg Kroah-Hartman, kernel, devicetree, NXP Linux Team, linux-serial

On Mon, Feb 10, 2020 at 2:50 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> Hello George,
>
> On Mon, Feb 10, 2020 at 01:29:49PM -0600, George Hilliard wrote:
> > @@ -1390,6 +1392,8 @@ static int imx_uart_startup(struct uart_port *port)
> >       ucr4 = imx_uart_readl(sport, UCR4) & ~UCR4_OREN;
> >       if (!sport->dma_is_enabled)
> >               ucr4 |= UCR4_OREN;
> > +     if (sport->inverted_rx)
> > +             ucr4 |= UCR4_INVR;
>
> You fail to clear this bit if .inverted_rx is false.

I believe this is taken care of by the SRST asserted slightly above
this - UCR* is reset by this. I see that this reset is also done in the
imx_uart_flush_buffer() implementation, but as I understand it, this
is a cleanup method that doesn't reconfigure much of the peripheral.

> >       imx_uart_writel(sport, ucr4, UCR4);
> >
> >       ucr2 = imx_uart_readl(sport, UCR2) & ~UCR2_ATEN;
> > @@ -1404,19 +1408,17 @@ static int imx_uart_startup(struct uart_port *port)
> >               ucr2 &= ~UCR2_RTSEN;
> >       imx_uart_writel(sport, ucr2, UCR2);
> >
> > +     ucr3 = imx_uart_readl(sport, UCR3);
> > +     if (sport->inverted_tx)
> > +             ucr3 |= UCR3_INVT;
>
> Also I think setting this bit here is a bit late because UCR2_TXEN was
> already set so changing UCR3_INVT probably results in a spike?!

Good point here; this should indeed be done before TX start.

George

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
  2020-02-10 23:03     ` George Hilliard
@ 2020-02-11  7:38       ` Uwe Kleine-König
  2020-02-11 16:18         ` George Hilliard
  0 siblings, 1 reply; 7+ messages in thread
From: Uwe Kleine-König @ 2020-02-11  7:38 UTC (permalink / raw)
  To: George Hilliard
  Cc: Greg Kroah-Hartman, kernel, devicetree, NXP Linux Team, linux-serial

Hello George,

On Mon, Feb 10, 2020 at 05:03:14PM -0600, George Hilliard wrote:
> On Mon, Feb 10, 2020 at 2:50 PM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > On Mon, Feb 10, 2020 at 01:29:49PM -0600, George Hilliard wrote:
> > > @@ -1390,6 +1392,8 @@ static int imx_uart_startup(struct uart_port *port)
> > >       ucr4 = imx_uart_readl(sport, UCR4) & ~UCR4_OREN;
> > >       if (!sport->dma_is_enabled)
> > >               ucr4 |= UCR4_OREN;
> > > +     if (sport->inverted_rx)
> > > +             ucr4 |= UCR4_INVR;
> >
> > You fail to clear this bit if .inverted_rx is false.
> 
> I believe this is taken care of by the SRST asserted slightly above
> this - UCR* is reset by this.

The i.MX6 manual states: Reset the transmit and receive state machines,
all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD and
UTS[6-3]. UCR* isn't mentioned here. So please at least confirm your
belief experimentally.

> I see that this reset is also done in the imx_uart_flush_buffer()
> implementation, but as I understand it, this is a cleanup method that
> doesn't reconfigure much of the peripheral.

The comment there even has the above list of registers. If the
experiment I suggested above should confirm your believe IMHO this
function needs fixing anyhow.
 
Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
  2020-02-11  7:38       ` Uwe Kleine-König
@ 2020-02-11 16:18         ` George Hilliard
  0 siblings, 0 replies; 7+ messages in thread
From: George Hilliard @ 2020-02-11 16:18 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Greg Kroah-Hartman, kernel, devicetree, NXP Linux Team, linux-serial

On Tue, Feb 11, 2020 at 1:38 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> Hello George,
>
> On Mon, Feb 10, 2020 at 05:03:14PM -0600, George Hilliard wrote:
> > On Mon, Feb 10, 2020 at 2:50 PM Uwe Kleine-König
> > <u.kleine-koenig@pengutronix.de> wrote:
> > > On Mon, Feb 10, 2020 at 01:29:49PM -0600, George Hilliard wrote:
> > > > @@ -1390,6 +1392,8 @@ static int imx_uart_startup(struct uart_port *port)
> > > >       ucr4 = imx_uart_readl(sport, UCR4) & ~UCR4_OREN;
> > > >       if (!sport->dma_is_enabled)
> > > >               ucr4 |= UCR4_OREN;
> > > > +     if (sport->inverted_rx)
> > > > +             ucr4 |= UCR4_INVR;
> > >
> > > You fail to clear this bit if .inverted_rx is false.
> >
> > I believe this is taken care of by the SRST asserted slightly above
> > this - UCR* is reset by this.
>
> The i.MX6 manual states: Reset the transmit and receive state machines,
> all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD and
> UTS[6-3]. UCR* isn't mentioned here. So please at least confirm your
> belief experimentally.

Oh, I see now - I misread "S" vs "C".  You are correct; I will send v3
with both changes.
Even with experimental evidence, there's no guarantee made by NXP, so
I'll handle it.

Thanks,
George

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 19:29 [PATCH v2 0/2] Implement support for inverted serial TX/RX on i.MX George Hilliard
2020-02-10 19:29 ` [PATCH v2 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
2020-02-10 19:29 ` [PATCH v2 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
2020-02-10 20:50   ` Uwe Kleine-König
2020-02-10 23:03     ` George Hilliard
2020-02-11  7:38       ` Uwe Kleine-König
2020-02-11 16:18         ` George Hilliard

Linux-Serial Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-serial/0 linux-serial/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-serial linux-serial/ https://lore.kernel.org/linux-serial \
		linux-serial@vger.kernel.org
	public-inbox-index linux-serial

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-serial


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git