diff mbox

[2/3] serial: mxs: enable the DMA only when the rts/cts is enabled

Message ID 1373857736-30108-2-git-send-email-b32955@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Huang Shijie July 15, 2013, 3:08 a.m. UTC
The originall DMA support works only when the rts/cts is enabled.
But after several patchs, the DMA support has lost this limit.

This patch adds an optional property for the uart DT node
which indicates the uart has rts and cts.

This patch also adds the check for rts/cts before we enable the DMA
for the uart.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
 .../bindings/tty/serial/fsl-mxs-auart.txt          |    3 +++
 drivers/tty/serial/mxs-auart.c                     |    5 ++++-
 2 files changed, 7 insertions(+), 1 deletions(-)

Comments

Uwe Kleine-König July 15, 2013, 8:27 a.m. UTC | #1
On Mon, Jul 15, 2013 at 11:08:55AM +0800, Huang Shijie wrote:
> The originall DMA support works only when the rts/cts is enabled.
s/originall/original/. I'd drop "the" and capitalize RTS/CTS.

> But after several patchs, the DMA support has lost this limit.
s/patchs/patches/, s/the //.

do you want to say that the driver fails to only enable DMA when RTS/CTS
are available; or that today the driver can handle DMA just fine even
without RTS/CTS? I interpret your commit log as the latter, your patch
implements the former however.

> This patch adds an optional property for the uart DT node
> which indicates the uart has rts and cts.
which indicates that the UART has RTS and CTS lines.

> This patch also adds the check for rts/cts before we enable the DMA
> for the uart.
> 
> Signed-off-by: Huang Shijie <b32955@freescale.com>
> ---
>  .../bindings/tty/serial/fsl-mxs-auart.txt          |    3 +++
>  drivers/tty/serial/mxs-auart.c                     |    5 ++++-
>  2 files changed, 7 insertions(+), 1 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt b/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt
> index 2c00ec6..ef82002 100644
> --- a/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt
> +++ b/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt
> @@ -10,6 +10,9 @@ Required properties:
>    Refer to dma.txt and fsl-mxs-dma.txt for details.
>  - dma-names: "rx" for RX channel, "tx" for TX channel.
>  
> +Optional properties:
> +- fsl,uart-has-rtscts : Indicate the uart has rts and cts
> +
>  Example:
>  auart0: serial@8006a000 {
>  	compatible = "fsl,imx28-auart", "fsl,imx23-auart";
> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
> index 465ef0b..27532fd 100644
> --- a/drivers/tty/serial/mxs-auart.c
> +++ b/drivers/tty/serial/mxs-auart.c
> @@ -134,6 +134,7 @@ enum mxs_auart_type {
>  struct mxs_auart_port {
>  	struct uart_port port;
>  
> +#define MXS_AUART_RTSCTS	1
>  #define MXS_AUART_DMA_ENABLED	0x2
>  #define MXS_AUART_DMA_TX_SYNC	2  /* bit 2 */
>  #define MXS_AUART_DMA_RX_READY	3  /* bit 3 */
> @@ -639,7 +640,7 @@ static void mxs_auart_settermios(struct uart_port *u,
>  		 * we can only implement the DMA support for auart
>  		 * in mx28.
>  		 */
> -		if (is_imx28_auart(s)) {
> +		if (is_imx28_auart(s) && (s->flags & MXS_AUART_RTSCTS)) {
>  			if (!mxs_auart_dma_init(s))
>  				/* enable DMA tranfer */
>  				ctrl2 |= AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE
> @@ -1001,6 +1002,8 @@ static int serial_mxs_probe_dt(struct mxs_auart_port *s,
>  	}
>  	s->port.line = ret;
>  
> +	if (of_get_property(np, "fsl,uart-has-rtscts", NULL))
> +		s->flags |= MXS_AUART_RTSCTS;
>  	return 0;
>  }
>  
> -- 
> 1.7.1
> 
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
Huang Shijie July 15, 2013, 8:41 a.m. UTC | #2
? 2013?07?15? 16:27, Uwe Kleine-König ??:
> do you want to say that the driver fails to only enable DMA when RTS/CTS
> are available; or that today the driver can handle DMA just fine even
> without RTS/CTS? I interpret your commit log as the latter, your patch
> implements the former however.
in the mxs-auart, if the RTS/CTS is not invalid, the DMA should be not 
enabled.

But current code lost the limit, a uart without the RTS/CTS may also 
enables the DMA in which case the uart
may does not run or run in a abnormal way.

thanks
Huang Shijie
Uwe Kleine-König July 15, 2013, 9:07 a.m. UTC | #3
Hello,

On Mon, Jul 15, 2013 at 04:41:25PM +0800, Huang Shijie wrote:
> ? 2013?07?15? 16:27, Uwe Kleine-König ??:
> >do you want to say that the driver fails to only enable DMA when RTS/CTS
> >are available; or that today the driver can handle DMA just fine even
> >without RTS/CTS? I interpret your commit log as the latter, your patch
> >implements the former however.
> in the mxs-auart, if the RTS/CTS is not invalid, the DMA should be
> not enabled.
> 
> But current code lost the limit, a uart without the RTS/CTS may also
> enables the DMA in which case the uart
> may does not run or run in a abnormal way.
So this sounds like a fix that should go into stable and so preferably
should be the first patch in your series.

Something like:

	serial: mxs-auart: DMA unreliable without RTS/CTS

	According to [add some document name here] DMA doesn't work
	reliable without hardware handshaking. So make DMA dependant on
	a newly introdused property "fsl,uart-has-rtscts".

	Cc: stable@kernel.org # [first affected version]

The flag is only used to decide if dma should be enabled. So I think an
in-code comment would be nice, too. Is it still correct to set
AUART_CTRL2_RTSEN and AUART_CTRL2_RTS and read AUART_STAT_CTS when
fsl,uart-has-rtscts is not provided?
(BTW, mxs_auart_set_mctrl has:

	u32 ctrl = readl(u->membase + AUART_CTRL2);

	ctrl &= ~(AUART_CTRL2_RTSEN | AUART_CTRL2_RTS);
        if (mctrl & TIOCM_RTS) {
                if (tty_port_cts_enabled(&u->state->port))
                        ctrl |= AUART_CTRL2_RTSEN;
                else
                        ctrl |= AUART_CTRL2_RTS;
        }

	s->ctrl = mctrl;

A comment for the diligent reader about the difference between RTSEN and
RTS would be nice. Also I wonder if shadowing mctrl is sensible and used
correctly here.)

Best regards
Uwe
Huang Shijie July 15, 2013, 10:53 a.m. UTC | #4
? 2013?07?15? 17:07, Uwe Kleine-König ??:
> Hello,
>
> On Mon, Jul 15, 2013 at 04:41:25PM +0800, Huang Shijie wrote:
>> ? 2013?07?15? 16:27, Uwe Kleine-König ??:
>>> do you want to say that the driver fails to only enable DMA when RTS/CTS
>>> are available; or that today the driver can handle DMA just fine even
>>> without RTS/CTS? I interpret your commit log as the latter, your patch
>>> implements the former however.
>> in the mxs-auart, if the RTS/CTS is not invalid, the DMA should be
>> not enabled.
>>
>> But current code lost the limit, a uart without the RTS/CTS may also
>> enables the DMA in which case the uart
>> may does not run or run in a abnormal way.
> So this sounds like a fix that should go into stable and so preferably
> should be the first patch in your series.
This patch depends on the first patch. :)
> Something like:
>
> 	serial: mxs-auart: DMA unreliable without RTS/CTS
>
> 	According to [add some document name here] DMA doesn't work
> 	reliable without hardware handshaking. So make DMA dependant on
> 	a newly introdused property "fsl,uart-has-rtscts".
>
> 	Cc: stable@kernel.org # [first affected version]
>
> The flag is only used to decide if dma should be enabled. So I think an
> in-code comment would be nice, too. Is it still correct to set
ok.
> AUART_CTRL2_RTSEN and AUART_CTRL2_RTS and read AUART_STAT_CTS when
> fsl,uart-has-rtscts is not provided?
i think it's correct. (if i have a imx28-evk board, i can test it.)

If you enable the RTS/CTS from the application, the 
tty_port_cts_enabled() will be true.
we will set the AUART_CTRL2_RTSEN in the end when the 
"fsl,uart-has-rtscts" is enabled.


> (BTW, mxs_auart_set_mctrl has:
>
> 	u32 ctrl = readl(u->membase + AUART_CTRL2);
>
> 	ctrl&= ~(AUART_CTRL2_RTSEN | AUART_CTRL2_RTS);
>          if (mctrl&  TIOCM_RTS) {
>                  if (tty_port_cts_enabled(&u->state->port))
>                          ctrl |= AUART_CTRL2_RTSEN;
>                  else
>                          ctrl |= AUART_CTRL2_RTS;
>          }
>
> 	s->ctrl = mctrl;
>
> A comment for the diligent reader about the difference between RTSEN and
> RTS would be nice. Also I wonder if shadowing mctrl is sensible and used
Please see the spec about the RTSEN and RTS.

RTSEN enable the flow control by the hardware;
RTS enable the flow control by the software.

thanks
Huang Shijie
> correctly here.)
>
> Best regards
> Uwe
>
Uwe Kleine-König July 16, 2013, 7:33 a.m. UTC | #5
On Mon, Jul 15, 2013 at 06:53:13PM +0800, Huang Shijie wrote:
> ? 2013?07?15? 17:07, Uwe Kleine-König ??:
> >Hello,
> >
> >On Mon, Jul 15, 2013 at 04:41:25PM +0800, Huang Shijie wrote:
> >>? 2013?07?15? 16:27, Uwe Kleine-König ??:
> >>>do you want to say that the driver fails to only enable DMA when RTS/CTS
> >>>are available; or that today the driver can handle DMA just fine even
> >>>without RTS/CTS? I interpret your commit log as the latter, your patch
> >>>implements the former however.
> >>in the mxs-auart, if the RTS/CTS is not invalid, the DMA should be
> >>not enabled.
> >>
> >>But current code lost the limit, a uart without the RTS/CTS may also
> >>enables the DMA in which case the uart
> >>may does not run or run in a abnormal way.
> >So this sounds like a fix that should go into stable and so preferably
> >should be the first patch in your series.
> This patch depends on the first patch. :)
But it's not a hard dependency.

> >Something like:
> >
> >	serial: mxs-auart: DMA unreliable without RTS/CTS
> >
> >	According to [add some document name here] DMA doesn't work
> >	reliable without hardware handshaking. So make DMA dependant on
> >	a newly introdused property "fsl,uart-has-rtscts".
> >
> >	Cc: stable@kernel.org # [first affected version]
> >
> >The flag is only used to decide if dma should be enabled. So I think an
> >in-code comment would be nice, too. Is it still correct to set
> ok.
> >AUART_CTRL2_RTSEN and AUART_CTRL2_RTS and read AUART_STAT_CTS when
> >fsl,uart-has-rtscts is not provided?
> i think it's correct. (if i have a imx28-evk board, i can test it.)
> 
> If you enable the RTS/CTS from the application, the
> tty_port_cts_enabled() will be true.
> we will set the AUART_CTRL2_RTSEN in the end when the
> "fsl,uart-has-rtscts" is enabled.
> 
> 
> >(BTW, mxs_auart_set_mctrl has:
> >
> >	u32 ctrl = readl(u->membase + AUART_CTRL2);
> >
> >	ctrl&= ~(AUART_CTRL2_RTSEN | AUART_CTRL2_RTS);
> >         if (mctrl&  TIOCM_RTS) {
> >                 if (tty_port_cts_enabled(&u->state->port))
> >                         ctrl |= AUART_CTRL2_RTSEN;
> >                 else
> >                         ctrl |= AUART_CTRL2_RTS;
> >         }
> >
> >	s->ctrl = mctrl;
> >
> >A comment for the diligent reader about the difference between RTSEN and
> >RTS would be nice. Also I wonder if shadowing mctrl is sensible and used
> Please see the spec about the RTSEN and RTS.
Right, it's not hard for me. Other might not have the manual handy, so
a comment telling:

> RTSEN enable the flow control by the hardware;
> RTS enable the flow control by the software.

would be nice.

Uwe
Huang Shijie July 16, 2013, 8:11 a.m. UTC | #6
? 2013?07?16? 15:33, Uwe Kleine-König ??:
>> This patch depends on the first patch. :)
> But it's not a hard dependency.
>
do you mean i should merge the patch 1 and patch 2 into a single patch?

>>> Something like:
>>>
>>> 	serial: mxs-auart: DMA unreliable without RTS/CTS
>>>
>>> 	According to [add some document name here] DMA doesn't work
>>> 	reliable without hardware handshaking. So make DMA dependant on
>>>   
>> Please see the spec about the RTSEN and RTS.
> Right, it's not hard for me. Other might not have the manual handy, so
> a comment telling:
>
>> RTSEN enable the flow control by the hardware;
>> RTS enable the flow control by the software.
> would be nice.
i think we need another patch to add this comment.

thanks
Huang Shijie
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt b/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt
index 2c00ec6..ef82002 100644
--- a/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt
+++ b/Documentation/devicetree/bindings/tty/serial/fsl-mxs-auart.txt
@@ -10,6 +10,9 @@  Required properties:
   Refer to dma.txt and fsl-mxs-dma.txt for details.
 - dma-names: "rx" for RX channel, "tx" for TX channel.
 
+Optional properties:
+- fsl,uart-has-rtscts : Indicate the uart has rts and cts
+
 Example:
 auart0: serial@8006a000 {
 	compatible = "fsl,imx28-auart", "fsl,imx23-auart";
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 465ef0b..27532fd 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -134,6 +134,7 @@  enum mxs_auart_type {
 struct mxs_auart_port {
 	struct uart_port port;
 
+#define MXS_AUART_RTSCTS	1
 #define MXS_AUART_DMA_ENABLED	0x2
 #define MXS_AUART_DMA_TX_SYNC	2  /* bit 2 */
 #define MXS_AUART_DMA_RX_READY	3  /* bit 3 */
@@ -639,7 +640,7 @@  static void mxs_auart_settermios(struct uart_port *u,
 		 * we can only implement the DMA support for auart
 		 * in mx28.
 		 */
-		if (is_imx28_auart(s)) {
+		if (is_imx28_auart(s) && (s->flags & MXS_AUART_RTSCTS)) {
 			if (!mxs_auart_dma_init(s))
 				/* enable DMA tranfer */
 				ctrl2 |= AUART_CTRL2_TXDMAE | AUART_CTRL2_RXDMAE
@@ -1001,6 +1002,8 @@  static int serial_mxs_probe_dt(struct mxs_auart_port *s,
 	}
 	s->port.line = ret;
 
+	if (of_get_property(np, "fsl,uart-has-rtscts", NULL))
+		s->flags |= MXS_AUART_RTSCTS;
 	return 0;
 }