devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bich HEMON <bich.hemon@st.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre TORGUE <alexandre.torgue@st.com>,
	Jiri Slaby <jslaby@suse.com>,
	"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Bich HEMON <bich.hemon@st.com>
Subject: [PATCH 19/20] serial: stm32: add dma rx callback
Date: Mon, 26 Jun 2017 12:49:17 +0000	[thread overview]
Message-ID: <1498481318-1894-20-git-send-email-bich.hemon@st.com> (raw)
In-Reply-To: <1498481318-1894-1-git-send-email-bich.hemon@st.com>

From: Bich Hemon <bich.hemon@st.com>

Initial usart driver behavior consists in looking for
chars received in dma rx buffer as soon as it gets the
interrupt telling that we received some data (RXNE or
RTO).

When stm32 dma is used combined with mdma, meaning that
the third dmamux property in the device tree is 0x1,
the received data are accumulated until the rx dma
transfer period (RX_BUF_L) is reached.

In that case, the usard driver will always get a maximum
residue for the rx dma transfer and its callback will
be called after each period completion to tell that
it can get a complete buffer: this is the purpose of
this patch.

Signed-off-by: Gerald Baeza <gerald.baeza@st.com>
---
 drivers/tty/serial/stm32-usart.c | 39 +++++++++++++++++++++++++++++++++------
 drivers/tty/serial/stm32-usart.h |  7 +++++++
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index d241056..06a92c8 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -124,14 +124,18 @@ static int stm32_pending_rx(struct uart_port *port, u32 *sr, int *last_res,
 	*sr = readl_relaxed(port->membase + ofs->isr);
 
 	if (threaded && stm32_port->rx_ch) {
+		if (stm32_port->rx_dma_cb == CALLBACK_CALLED)
+			return 1;
 		status = dmaengine_tx_status(stm32_port->rx_ch,
 					     stm32_port->rx_ch->cookie,
 					     &state);
 		if ((status == DMA_IN_PROGRESS) &&
-		    (*last_res != state.residue))
+		    (*last_res != state.residue)) {
+			stm32_port->rx_dma_cb = CALLBACK_IGNORED;
 			return 1;
-		else
+		} else {
 			return 0;
+		}
 	} else if (*sr & USART_SR_RXNE) {
 		return 1;
 	}
@@ -147,8 +151,11 @@ static int stm32_pending_rx(struct uart_port *port, u32 *sr, int *last_res,
 
 	if (stm32_port->rx_ch) {
 		c = stm32_port->rx_buf[RX_BUF_L - (*last_res)--];
-		if ((*last_res) == 0)
+		if ((*last_res) == 0) {
 			*last_res = RX_BUF_L;
+			if (stm32_port->rx_dma_cb == CALLBACK_CALLED)
+				stm32_port->rx_dma_cb = CALLBACK_NOT_CALLED;
+		}
 		return c;
 	} else {
 		return readl_relaxed(port->membase + ofs->rdr);
@@ -238,6 +245,27 @@ static void stm32_tx_dma_complete(void *arg)
 	stm32_transmit_chars(port);
 }
 
+static void stm32_rx_dma_complete(void *arg)
+{
+	struct uart_port *port = arg;
+	struct stm32_port *stm32port = to_stm32_port(port);
+	unsigned long flags;
+
+	spin_lock_irqsave(&port->lock, flags);
+
+	/*
+	 * If the dma controller is sending the data on
+	 * the fly then we have CALLBACK_IGNORED
+	 */
+
+	if (stm32port->rx_dma_cb == CALLBACK_NOT_CALLED) {
+		stm32port->rx_dma_cb = CALLBACK_CALLED;
+		stm32_receive_chars(port, true);
+	}
+
+	spin_unlock_irqrestore(&port->lock, flags);
+}
+
 static void stm32_transmit_chars_pio(struct uart_port *port)
 {
 	struct stm32_port *stm32_port = to_stm32_port(port);
@@ -897,9 +925,8 @@ static int stm32_of_dma_rx_probe(struct stm32_port *stm32port,
 		goto config_err;
 	}
 
-	/* No callback as dma buffer is drained on usart interrupt */
-	desc->callback = NULL;
-	desc->callback_param = NULL;
+	desc->callback = stm32_rx_dma_complete;
+	desc->callback_param = port;
 
 	/* Push current DMA transaction in the pending queue */
 	cookie = dmaengine_submit(desc);
diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
index 5137e68..f8cad09 100644
--- a/drivers/tty/serial/stm32-usart.h
+++ b/drivers/tty/serial/stm32-usart.h
@@ -242,6 +242,12 @@ struct stm32_usart_info stm32h7_info = {
 #define RX_BUF_P RX_BUF_L	 /* dma rx buffer period     */
 #define TX_BUF_L RX_BUF_L	 /* dma tx buffer length     */
 
+enum dma_cb {
+	CALLBACK_NOT_CALLED,
+	CALLBACK_CALLED,
+	CALLBACK_IGNORED,
+};
+
 struct stm32_port {
 	struct uart_port port;
 	struct clk *clk;
@@ -257,6 +263,7 @@ struct stm32_port {
 	unsigned char *tx_buf;   /* dma tx buffer cpu address */
 	u32 rx_irq;		 /* USART_CR1_RXNEIE or RTOIE */
 	int last_res;
+	enum dma_cb rx_dma_cb;	 /* dma rx callback status    */
 	bool tx_dma_busy;	 /* dma tx busy               */
 	bool hw_flow_control;
 	bool fifoen;
-- 
1.9.1

      parent reply	other threads:[~2017-06-26 12:49 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-26 12:49 [PATCH 00/20] Update STM32 usart driver Bich HEMON
2017-06-26 12:49 ` [PATCH 02/20] dt-bindings: serial: each stm32 usart needs an alias Bich HEMON
     [not found]   ` <1498481318-1894-3-git-send-email-bich.hemon-qxv4g6HH51o@public.gmane.org>
2017-06-28 18:06     ` Rob Herring
2017-06-26 12:49 ` [PATCH 01/20] serial: stm32: adding fifo support Bich HEMON
2017-06-26 12:49 ` [PATCH 05/20] serial: stm32: add debugfs Bich HEMON
     [not found] ` <1498481318-1894-1-git-send-email-bich.hemon-qxv4g6HH51o@public.gmane.org>
2017-06-26 12:49   ` [PATCH 03/20] serial: stm32: fix multi ports management Bich HEMON
2017-06-26 12:49   ` [PATCH 10/20] serial: stm32: fix dma receive Bich HEMON
2017-06-26 12:49   ` [PATCH 13/20] serial: stm32: fix error handling in probe Bich HEMON
2017-06-29 14:50     ` Greg Kroah-Hartman
2017-06-26 12:49   ` [PATCH 15/20] serial: stm32: Add wakeup mechanism Bich HEMON
2017-06-26 12:49   ` [PATCH 14/20] dt-bindings: serial: document option wake-up interrupt for STM32 USART Bich HEMON
     [not found]     ` <1498481318-1894-15-git-send-email-bich.hemon-qxv4g6HH51o@public.gmane.org>
2017-06-28 18:10       ` Rob Herring
2017-06-29 14:50     ` Greg Kroah-Hartman
2017-06-26 12:49   ` [PATCH 17/20] dt-bindings: serial: stm32: add dma using note Bich HEMON
     [not found]     ` <1498481318-1894-18-git-send-email-bich.hemon-qxv4g6HH51o@public.gmane.org>
2017-06-28 22:26       ` Rob Herring
2017-06-29 14:50       ` Greg Kroah-Hartman
2017-06-26 12:49   ` [PATCH 20/20] serial: stm32: fix rx interrupt handling in startup Bich HEMON
2017-06-29 15:09   ` [PATCH 00/20] Update STM32 usart driver Alexandre Torgue
2017-06-26 12:49 ` [PATCH 04/20] serial: stm32: make fifoen as property for each port Bich HEMON
2017-06-26 12:49 ` [PATCH 06/20] serial: stm32: fix pio transmit timeout Bich HEMON
2017-06-26 12:49 ` [PATCH 07/20] serial: stm32: less messages on dma alloc error Bich HEMON
2017-06-26 12:49 ` [PATCH 09/20] serial: stm32: fix end of transfer Bich HEMON
2017-06-26 12:49 ` [PATCH 08/20] serial: stm32: timeout interrupt using with dma Bich HEMON
2017-06-26 12:49 ` [PATCH 11/20] serial: stm32: add RTS support Bich HEMON
2017-06-26 12:49 ` [PATCH 12/20] serial: stm32: fix last_res value Bich HEMON
2017-06-26 12:49 ` [PATCH 16/20] serial: stm32: fix fifo usage Bich HEMON
2017-06-26 12:49 ` [PATCH 18/20] serial: stm32: update dma buffers length Bich HEMON
2017-06-26 12:49 ` Bich HEMON [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=1498481318-1894-20-git-send-email-bich.hemon@st.com \
    --to=bich.hemon@st.com \
    --cc=alexandre.torgue@st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=robh+dt@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 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).