All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: George Hilliard <ghilliard@kopismobile.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-serial@vger.kernel.org, devicetree@vger.kernel.org,
	NXP Linux Team <linux-imx@nxp.com>,
	kernel@pengutronix.de
Subject: Re: [PATCH v3 2/2] tty: imx serial: Implement support for reversing TX and RX polarity
Date: Wed, 12 Feb 2020 21:47:40 +0100	[thread overview]
Message-ID: <20200212204740.wc4pibfajxgi5tfp@pengutronix.de> (raw)
In-Reply-To: <20200212163538.3006-3-ghilliard@kopismobile.com>

On Wed, Feb 12, 2020 at 10:35:38AM -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.
> 
> 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
> 
>  drivers/tty/serial/imx.c | 28 +++++++++++++++++++++++-----
>  1 file changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 0c6c63166250..205627bcad66 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,8 +1392,22 @@ 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;
> +	else
> +		ucr4 &= ~UCR4_INVR;

Maybe clear UCR4_INVR in the same way as UCR4_OREN is cleared just
above?

>  	imx_uart_writel(sport, ucr4, UCR4);
>  
> +	/*
> +	 * configure tx polarity before enabling tx
> +	 */
> +	ucr3 = imx_uart_readl(sport, UCR3);
> +	if (sport->inverted_tx)
> +		ucr3 |= UCR3_INVT;
> +	else
> +		ucr3 &= ~UCR3_INVT;
> +	imx_uart_writel(sport, ucr3, UCR3);
> +
>  	ucr2 = imx_uart_readl(sport, UCR2) & ~UCR2_ATEN;
>  	ucr2 |= (UCR2_RXEN | UCR2_TXEN);
>  	if (!sport->have_rtscts)
> @@ -1405,10 +1421,6 @@ static int imx_uart_startup(struct uart_port *port)
>  	imx_uart_writel(sport, ucr2, UCR2);
>  
>  	if (!imx_uart_is_imx1(sport)) {

If this complete if block would be moved up, you only need to write this
register once.

> -		u32 ucr3;
> -
> -		ucr3 = imx_uart_readl(sport, UCR3);
> -
>  		ucr3 |= UCR3_DTRDEN | UCR3_RI | UCR3_DCD;
>  
>  		if (sport->dte_mode)

Best regards
Uwe

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

      reply	other threads:[~2020-02-12 20:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 16:35 [PATCH v3 0/2] Implement support for inverted serial TX/RX on i.MX George Hilliard
2020-02-12 16:35 ` [PATCH v3 1/2] dt-bindings: serial: document fsl,inverted-tx and -rx options George Hilliard
2020-02-18 23:07   ` Rob Herring
2020-02-12 16:35 ` [PATCH v3 2/2] tty: imx serial: Implement support for reversing TX and RX polarity George Hilliard
2020-02-12 20:47   ` Uwe Kleine-König [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=20200212204740.wc4pibfajxgi5tfp@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=devicetree@vger.kernel.org \
    --cc=ghilliard@kopismobile.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-imx@nxp.com \
    --cc=linux-serial@vger.kernel.org \
    /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.