devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Implement support for inverted serial TX/RX on i.MX
@ 2020-02-26 22:23 George Hilliard
  2020-02-26 22:23 ` [PATCH v4 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
  2020-02-26 22:23 ` [PATCH v4 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
  0 siblings, 2 replies; 4+ messages in thread
From: George Hilliard @ 2020-02-26 22:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: George Hilliard, linux-serial, devicetree, NXP Linux Team, 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.

v4 cleans up the bit manipulation in v3; see previous series at
https://lore.kernel.org/linux-serial/20200212163538.3006-1-ghilliard@kopismobile.com/

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                      | 44 ++++++++++++-------
 2 files changed, 32 insertions(+), 16 deletions(-)

-- 
2.25.0


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

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

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>
Reviewed-by: Rob Herring <robh@kernel.org>
---
v1..v2: Removed confidentiality spam
v2..v4: No changes

 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 related	[flat|nested] 4+ messages in thread

* [PATCH v4 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
  2020-02-26 22:23 [PATCH v4 0/2] Implement support for inverted serial TX/RX on i.MX George Hilliard
  2020-02-26 22:23 ` [PATCH v4 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
@ 2020-02-26 22:23 ` George Hilliard
  2020-02-27  7:53   ` Uwe Kleine-König
  1 sibling, 1 reply; 4+ messages in thread
From: George Hilliard @ 2020-02-26 22:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: George Hilliard, linux-serial, devicetree, NXP Linux Team, 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.

As part of this change, make the writes of the various registers more
uniform by moving the UCR3 block up near the other registers' blocks,
since the INVT bit must be set before enabling the peripheral.

Signed-off-by: George Hilliard <ghilliard@kopismobile.com>
---
v1..v2: Remove confidentiality spam
v2..v3: Set *and* clear register, and do it before TX enable
v3..v4: Clean up bit manipulation; move UCR3 block so it's written once

 drivers/tty/serial/imx.c | 44 +++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 0c6c63166250..81a981849a4b 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)
@@ -1387,11 +1389,29 @@ static int imx_uart_startup(struct uart_port *port)
 
 	imx_uart_writel(sport, ucr1, UCR1);
 
-	ucr4 = imx_uart_readl(sport, UCR4) & ~UCR4_OREN;
+	ucr4 = imx_uart_readl(sport, UCR4) & ~(UCR4_OREN | UCR4_INVR);
 	if (!sport->dma_is_enabled)
 		ucr4 |= UCR4_OREN;
+	if (sport->inverted_rx)
+		ucr4 |= UCR4_INVR;
 	imx_uart_writel(sport, ucr4, UCR4);
 
+	ucr3 = imx_uart_readl(sport, UCR3) & ~UCR3_INVT;
+	/*
+	 * configure tx polarity before enabling tx
+	 */
+	if (sport->inverted_tx)
+		ucr3 |= UCR3_INVT;
+
+	if (!imx_uart_is_imx1(sport)) {
+		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);
+
 	ucr2 = imx_uart_readl(sport, UCR2) & ~UCR2_ATEN;
 	ucr2 |= (UCR2_RXEN | UCR2_TXEN);
 	if (!sport->have_rtscts)
@@ -1404,20 +1424,6 @@ static int imx_uart_startup(struct uart_port *port)
 		ucr2 &= ~UCR2_RTSEN;
 	imx_uart_writel(sport, ucr2, UCR2);
 
-	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);
-	}
-
 	/*
 	 * Enable modem status interrupts
 	 */
@@ -2184,6 +2190,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 related	[flat|nested] 4+ messages in thread

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

On Wed, Feb 26, 2020 at 04:23:19PM -0600, George Hilliard wrote:
> 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.
> 
> As part of this change, make the writes of the various registers more
> uniform by moving the UCR3 block up near the other registers' blocks,
> since the INVT bit must be set before enabling the peripheral.
> 
> Signed-off-by: George Hilliard <ghilliard@kopismobile.com>

LGTM,

Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>

Thanks
Uwe

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

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

end of thread, other threads:[~2020-02-27  7:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 22:23 [PATCH v4 0/2] Implement support for inverted serial TX/RX on i.MX George Hilliard
2020-02-26 22:23 ` [PATCH v4 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
2020-02-26 22:23 ` [PATCH v4 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
2020-02-27  7:53   ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).