From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>,
Magnus Damm <magnus.damm@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
linux-renesas-soc@vger.kernel.org, linux-serial@vger.kernel.org,
Milan Stevanovic <milan.stevanovic@se.com>,
Jimmy Lalande <jimmy.lalande@se.com>,
Pascal Eberhard <pascal.eberhard@se.com>,
Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Herve Codina <herve.codina@bootlin.com>,
Clement Leger <clement.leger@bootlin.com>,
Ilpo Jarvinen <ilpo.jarvinen@linux.intel.com>,
Phil Edworthy <phil.edworthy@renesas.com>
Subject: Re: [PATCH v5 09/11] serial: 8250: dw: Add support for DMA flow controlling devices
Date: Wed, 13 Apr 2022 13:58:56 +0300 [thread overview]
Message-ID: <Ylas8KubwVLEc2sz@smile.fi.intel.com> (raw)
In-Reply-To: <20220413075141.72777-10-miquel.raynal@bootlin.com>
On Wed, Apr 13, 2022 at 09:51:39AM +0200, Miquel Raynal wrote:
> From: Phil Edworthy <phil.edworthy@renesas.com>
>
> DW based controllers like the one on Renesas RZ/N1 must be programmed as
> flow controllers when using DMA.
>
> * Table 11.45 of the system manual, "Flow Control Combinations", states
> that using UART with DMA requires setting the DMA in the peripheral
> flow controller mode regardless of the direction.
>
> * Chapter 11.6.1.3 of the system manual, "Basic Interface Definitions",
> explains that the burst size in the above case must be configured in
> the peripheral's register DEST/SRC_BURST_SIZE.
>
> Experiments shown that upon Rx timeout, the DMA transaction needed to be
> manually cleared as well.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
One remark below.
> Signed-off-by: Phil Edworthy <phil.edworthy@renesas.com>
> Co-developed-by: Miquel Raynal <miquel.raynal@bootlin.com>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
> drivers/tty/serial/8250/8250_dw.c | 64 +++++++++++++++++++++++++++++++
> 1 file changed, 64 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
> index 238bcdf1bab0..f8e762e3ef0f 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -34,16 +34,28 @@
>
> /* Offsets for the DesignWare specific registers */
> #define DW_UART_USR 0x1f /* UART Status Register */
> +#define DW_UART_DMASA 0xa8 /* DMA Software Ack */
> +#define RZN1_UART_TDMACR 0x10c /* DMA Control Register Transmit Mode */
> +#define RZN1_UART_RDMACR 0x110 /* DMA Control Register Receive Mode */
This group is different to the DW and OCTEON, but OCTEON starts with smaller
number. I dunno how this will be in the future and if it makes sense to order
now, i.e. to put these two after OCTEON group. In either case I'm fine.
> #define OCTEON_UART_USR 0x27 /* UART Status Register */
>
> /* DesignWare specific register fields */
> #define DW_UART_MCR_SIRE BIT(6)
>
> +/* Renesas specific register fields */
> +#define RZN1_UART_xDMACR_DMA_EN BIT(0)
> +#define RZN1_UART_xDMACR_1_WORD_BURST (0 << 1)
> +#define RZN1_UART_xDMACR_4_WORD_BURST (1 << 1)
> +#define RZN1_UART_xDMACR_8_WORD_BURST (3 << 1)
> +#define RZN1_UART_xDMACR_BLK_SZ(x) ((x) << 3)
> +
> /* Quirks */
> #define DW_UART_QUIRK_OCTEON BIT(0)
> #define DW_UART_QUIRK_ARMADA_38X BIT(1)
> #define DW_UART_QUIRK_SKIP_SET_RATE BIT(2)
> +#define DW_UART_QUIRK_IS_DMA_FC BIT(3)
>
> static inline struct dw8250_data *clk_to_dw8250_data(struct notifier_block *nb)
> {
> @@ -226,6 +238,7 @@ static int dw8250_handle_irq(struct uart_port *p)
> struct dw8250_data *d = to_dw8250_data(p->private_data);
> unsigned int iir = p->serial_in(p, UART_IIR);
> bool rx_timeout = (iir & 0x3f) == UART_IIR_RX_TIMEOUT;
> + unsigned int quirks = d->pdata->quirks;
> unsigned int status;
> unsigned long flags;
>
> @@ -249,6 +262,15 @@ static int dw8250_handle_irq(struct uart_port *p)
> spin_unlock_irqrestore(&p->lock, flags);
> }
>
> + /* Manually stop the Rx DMA transfer when acting as flow controller */
> + if (quirks & DW_UART_QUIRK_IS_DMA_FC && up->dma && up->dma->rx_running && rx_timeout) {
> + status = p->serial_in(p, UART_LSR);
> + if (status & (UART_LSR_DR | UART_LSR_BI)) {
> + dw8250_writel_ext(p, RZN1_UART_RDMACR, 0);
> + dw8250_writel_ext(p, DW_UART_DMASA, 1);
> + }
> + }
> +
> if (serial8250_handle_irq(p, iir))
> return 1;
>
> @@ -372,6 +394,42 @@ static bool dw8250_idma_filter(struct dma_chan *chan, void *param)
> return param == chan->device->dev;
> }
>
> +static u32 dw8250_rzn1_get_dmacr_burst(int max_burst)
> +{
> + if (max_burst >= 8)
> + return RZN1_UART_xDMACR_8_WORD_BURST;
> + else if (max_burst >= 4)
> + return RZN1_UART_xDMACR_4_WORD_BURST;
> + else
> + return RZN1_UART_xDMACR_1_WORD_BURST;
> +}
> +
> +static void dw8250_prepare_tx_dma(struct uart_8250_port *p)
> +{
> + struct uart_port *up = &p->port;
> + struct uart_8250_dma *dma = p->dma;
> + u32 val;
> +
> + dw8250_writel_ext(up, RZN1_UART_TDMACR, 0);
> + val = dw8250_rzn1_get_dmacr_burst(dma->txconf.dst_maxburst) |
> + RZN1_UART_xDMACR_BLK_SZ(dma->tx_size) |
> + RZN1_UART_xDMACR_DMA_EN;
> + dw8250_writel_ext(up, RZN1_UART_TDMACR, val);
> +}
> +
> +static void dw8250_prepare_rx_dma(struct uart_8250_port *p)
> +{
> + struct uart_port *up = &p->port;
> + struct uart_8250_dma *dma = p->dma;
> + u32 val;
> +
> + dw8250_writel_ext(up, RZN1_UART_RDMACR, 0);
> + val = dw8250_rzn1_get_dmacr_burst(dma->rxconf.src_maxburst) |
> + RZN1_UART_xDMACR_BLK_SZ(dma->rx_size) |
> + RZN1_UART_xDMACR_DMA_EN;
> + dw8250_writel_ext(up, RZN1_UART_RDMACR, val);
> +}
> +
> static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
> {
> struct device_node *np = p->dev->of_node;
> @@ -404,6 +462,12 @@ static void dw8250_quirks(struct uart_port *p, struct dw8250_data *data)
> p->serial_out = dw8250_serial_out38x;
> if (quirks & DW_UART_QUIRK_SKIP_SET_RATE)
> p->set_termios = dw8250_do_set_termios;
> + if (quirks & DW_UART_QUIRK_IS_DMA_FC) {
> + data->data.dma.txconf.device_fc = 1;
> + data->data.dma.rxconf.device_fc = 1;
> + data->data.dma.prepare_tx_dma = dw8250_prepare_tx_dma;
> + data->data.dma.prepare_rx_dma = dw8250_prepare_rx_dma;
> + }
>
> } else if (acpi_dev_present("APMC0D08", NULL, -1)) {
> p->iotype = UPIO_MEM32;
> --
> 2.27.0
>
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2022-04-13 11:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-13 7:51 [PATCH v5 00/11] serial: 8250: dw: RZN1 DMA support Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 01/11] serial: 8250: dw: Move definitions to the shared header Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 02/11] serial: 8250: dw: Use the device API Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 03/11] serial: 8250: dw: Create a more generic platform data structure Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 04/11] serial: 8250: dw: Move the USR register to pdata Miquel Raynal
2022-04-13 10:50 ` Andy Shevchenko
2022-04-13 7:51 ` [PATCH v5 05/11] serial: 8250: dw: Allow to use a fallback CPR value if not synthesized Miquel Raynal
2022-04-13 10:53 ` Andy Shevchenko
2022-04-13 7:51 ` [PATCH v5 06/11] serial: 8250: dma: Allow driver operations before starting DMA transfers Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 07/11] serial: 8250: dw: Introduce an rx_timeout variable in the IRQ path Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 08/11] serial: 8250: dw: Move the IO accessors to 8250_dwlib.h Miquel Raynal
2022-04-13 10:55 ` Andy Shevchenko
2022-04-13 7:51 ` [PATCH v5 09/11] serial: 8250: dw: Add support for DMA flow controlling devices Miquel Raynal
2022-04-13 10:58 ` Andy Shevchenko [this message]
2022-04-13 7:51 ` [PATCH v5 10/11] serial: 8250: dw: Improve RZN1 support Miquel Raynal
2022-04-13 7:51 ` [PATCH v5 11/11] ARM: dts: r9a06g032: Fill the UART DMA properties Miquel Raynal
2022-04-15 9:36 ` [PATCH v5 00/11] serial: 8250: dw: RZN1 DMA support Greg Kroah-Hartman
2022-04-20 8:56 ` Miquel Raynal
2022-04-21 9:30 ` Miquel Raynal
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=Ylas8KubwVLEc2sz@smile.fi.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=clement.leger@bootlin.com \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=herve.codina@bootlin.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jimmy.lalande@se.com \
--cc=jirislaby@kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=milan.stevanovic@se.com \
--cc=miquel.raynal@bootlin.com \
--cc=pascal.eberhard@se.com \
--cc=phil.edworthy@renesas.com \
--cc=thomas.petazzoni@bootlin.com \
/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).