Re: [PATCH 6/7] serial: 8250_dw: Add support for RZ/N1 DMA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Mar 10, 2022 at 05:16:49PM +0100, Miquel Raynal wrote:
> From: Phil Edworthy <phil.edworthy@xxxxxxxxxxx>
> 
> The Renesas RZ/N1 devices have a modified Synopsys DW UART. The
> modifications are mostly related to the DMA handlnig, and so this patch
> adds support for DMA.

> The RZ/N1 UART must be used with the peripheral as the flow
> controller.

(1)

> This means the DMA length should also be programmed into
> UART registers.

(2)

Hmm... DMA controller vs. Peripheral flow control is about signalling on the HW
level on who starts the transaction. This is programmed in the DMA controller
device driver. Is it what you do in DesignWare DMA patch series?

Ah, I see now, you set fc here.

But still it's not clear how (2) and (1) are related.

> Aside from this, there are some points to note about DMA burst sizes.
> First, DMA must not remove all of the data from the rx FIFO. Otherwise,
> we do not get a 'character timeout' interrupt, and so do not know that
> we should push data up the serial stack. Therefore, we have the rx
> threshold for generating an interrupt set to half the FIFO depth (this
> is the default for 16550A), and set the DMA burst size when reading the
> FIFO to a quarter of the FIFO depth.
> 
> Second, when transmitting data using DMA, the burst size must be limited
> to 1 byte to handle then case when transmitting just 1 byte. Otherwise
> the DMA doesn't complete the burst, and nothing happens.

...

> +/* Offsets for the Renesas RZ/N1 DesignWare specific registers */
> +/* DMA Software Ack */
> +#define RZN1_UART_DMASA			0xa8

Is it specific to Renesas? IIRC it's Synopsys DesignWare register, makes
sense to use appropriate prefix or no prefix.

...

> +#define RZN1_UART_xDMACR_1_WORD_BURST	0
> +#define RZN1_UART_xDMACR_4_WORD_BURST	BIT(1)
> +#define RZN1_UART_xDMACR_8_WORD_BURST	(BIT(1) | BIT(2))

This looks like incorrect use of BIT() macro.
Please, use plain decimal integers. Something like

	1	(0 << 1)
	4	(1 << 1)
	8	(3 << 1)

If I'm mistaken, describe the meaning of each bit there.

...

> +static void rzn1_8250_handle_irq(struct uart_port *port, unsigned int iir)
> +{
> +	struct uart_8250_port *up = up_to_u8250p(port);
> +	struct uart_8250_dma *dma = up->dma;
> +	unsigned char status;

> +	if (up->dma && dma->rx_running) {

With

	if (!)up->dma && dma->rx_running))
		return;

maybe easier to read the rest.

> +		status = port->serial_in(port, UART_LSR);
> +		if (status & (UART_LSR_DR | UART_LSR_BI)) {
> +			/* Stop the DMA transfer */
> +			writel(0, port->membase + RZN1_UART_RDMACR);
> +			writel(1, port->membase + RZN1_UART_DMASA);
> +		}
> +	}
> +}

...

> +	if (d->is_rzn1 && ((iir & 0x3f) == UART_IIR_RX_TIMEOUT))
> +		rzn1_8250_handle_irq(p, iir);

A few years ago it was a discussion about broken timeout on some platforms
with Synopsys DesignWare UART + DMA. Can it be that this is actually required
for all of them that uses same combination of IPs?

...

> +static u32 rzn1_get_dmacr_burst(int max_burst)
> +{

> +	u32 val = 0;

Redundant assignment and variable itself. Use return statements directly.

> +	if (max_burst >= 8)
> +		val = RZN1_UART_xDMACR_8_WORD_BURST;
> +	else if (max_burst >= 4)
> +		val = RZN1_UART_xDMACR_4_WORD_BURST;
> +	else
> +		val = RZN1_UART_xDMACR_1_WORD_BURST;
> +
> +	return val;
> +}

...

> +static int rzn1_dw8250_tx_dma(struct uart_8250_port *p)
> +{
> +	struct uart_port		*up = &p->port;
> +	struct uart_8250_dma		*dma = p->dma;
> +	struct circ_buf			*xmit = &p->port.state->xmit;
> +	int tx_size;
> +	u32 val;
> +
> +	if (uart_tx_stopped(&p->port) || dma->tx_running ||
> +	    uart_circ_empty(xmit))
> +		return 0;
> +
> +	tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);

> +	writel(0, up->membase + RZN1_UART_TDMACR);
> +	val = rzn1_get_dmacr_burst(dma->txconf.dst_maxburst);
> +	val |= tx_size << RZN1_UART_xDMACR_BLK_SZ_OFFSET;
> +	val |= RZN1_UART_xDMACR_DMA_EN;
> +	writel(val, up->membase + RZN1_UART_TDMACR);

Can this be added as a callback to the serial8250_tx_dma()?
Ditto for Rx counterpart.

> +	return serial8250_tx_dma(p);
> +}

...

> +	data->is_rzn1 = of_device_is_compatible(dev->of_node, "renesas,rzn1-uart");

Device property API.

>  	/* Always ask for fixed clock rate from a property. */
>  	device_property_read_u32(dev, "clock-frequency", &p->uartclk);

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux