Re: [PATCH] serial: imx: disable DMA for RS-485 on i.MX6 SMP

From: Fabio Estevam
Date: Tue Jun 20 2017 - 19:49:38 EST


Hi Clemens,

On Tue, Jun 20, 2017 at 1:13 PM, Fabio Estevam <festevam@xxxxxxxxx> wrote:

> The subject gives the impression that the DMA will only be disabled
> for RS485, but the impact of this change is wider.
>
> For example: if I have a mx6q system with a Bluetooth serial
> connection I can no longer use DMA with your change applied.
>
> Ideally we should fix the RS485 DMA bug. If that is not possible, then
> at least we need to restrict this change to the RS485 case.
>
> Maybe we need to pass "linux,rs485-enabled-at-boot-time" in device
> tree and then use this property to deceide if DMA will be enabled or
> not:
>
> if (!uart_console(port) && !sport->dma_is_inited && !sport->rs485_enabled)

Could you please test the two attached patches and see if it solves the issue?

Unfortunately I no longer have access to the RS485 half-duplex board.

Just make sure to pass 'linux,rs485-enabled-at-boot-time' in your
device tree, thanks.
From 0a36d212228a8d093a03bbab94e9e6ffe99c87c3 Mon Sep 17 00:00:00 2001
From: Fabio Estevam <fabio.estevam@xxxxxxx>
Date: Tue, 20 Jun 2017 20:29:13 -0300
Subject: [PATCH 1/2] serial: imx: Support 'linux,rs485-enabled-at-boot-time'

According to Documentation/devicetree/bindings/serial/rs485.txt, the
"linux,rs485-enabled-at-boot-time" property can be used to indicate
that RS485 is enabled during boot time.

Add support for it in the driver.

Signed-off-by: Fabio Estevam <fabio.estevam@xxxxxxx>
---
drivers/tty/serial/imx.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 92606b1..90f8a5d 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2123,6 +2123,9 @@ static int serial_imx_probe(struct platform_device *pdev)
sport->port.rs485_config = imx_rs485_config;
sport->port.rs485.flags =
SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX;
+ if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
+ sport->port.rs485.flags |= SER_RS485_ENABLED;
+
sport->port.flags = UPF_BOOT_AUTOCONF;
init_timer(&sport->timer);
sport->timer.function = imx_timeout;
--
2.7.4

From bf63a07c546ceed3d2c3d203d75e87001144423f Mon Sep 17 00:00:00 2001
From: Fabio Estevam <fabio.estevam@xxxxxxx>
Date: Tue, 20 Jun 2017 20:36:32 -0300
Subject: [PATCH 2/2] serial: imx: Disable DMA for RS485

Currently DMA support for half-duplex RS-485 does not work on i.MX6
as instead the real data being sent out, the rest of the transmit buffer
is sent (xmit->tail jumps over xmit->head in imx_transmit_buffer and
UART_XMIT_SIZE bytes are sent out).

Disable DMA for the RS485 case until a proper fix is found.

Reported-by: Clemens Gruber <clemens.gruber@xxxxxxxxxxxx>
Signed-off-by: Fabio Estevam <fabio.estevam@xxxxxxx>
---
drivers/tty/serial/imx.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 90f8a5d..4812e11 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -213,6 +213,7 @@ struct imx_port {
struct clk *clk_ipg;
struct clk *clk_per;
const struct imx_uart_data *devdata;
+ bool rs485_enabled_at_boot;

struct mctrl_gpios *gpios;

@@ -1278,7 +1279,8 @@ static int imx_startup(struct uart_port *port)
writel(temp & ~UCR4_DREN, sport->port.membase + UCR4);

/* Can we enable the DMA support? */
- if (!uart_console(port) && !sport->dma_is_inited)
+ if (!uart_console(port) && !sport->dma_is_inited &&
+ !sport->rs485_enabled_at_boot)
imx_uart_dma_init(sport);

spin_lock_irqsave(&sport->port.lock, flags);
@@ -2087,6 +2089,7 @@ static void serial_imx_probe_pdata(struct imx_port *sport,

static int serial_imx_probe(struct platform_device *pdev)
{
+ struct device_node *np = pdev->dev.of_node;
struct imx_port *sport;
void __iomem *base;
int ret = 0, reg;
@@ -2123,8 +2126,10 @@ static int serial_imx_probe(struct platform_device *pdev)
sport->port.rs485_config = imx_rs485_config;
sport->port.rs485.flags =
SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX;
- if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
+ if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL)) {
sport->port.rs485.flags |= SER_RS485_ENABLED;
+ sport->rs485_enabled_at_boot = true;
+ }

sport->port.flags = UPF_BOOT_AUTOCONF;
init_timer(&sport->timer);
--
2.7.4