Skip to content

Commit

Permalink
tty: serial: fsl_lpuart: Introduce lpuart_tx_dma_startup()
Browse files Browse the repository at this point in the history
Code configure DMA TX path in lpuart_startup(), lpuart32_startup() and
lpuart_resume() is doing exactly the same thing, so move it into a
standalone subroutine.

Signed-off-by: Andrey Smirnov <[email protected]>
Cc: Stefan Agner <[email protected]>
Cc: Chris Healy <[email protected]>
Cc: Cory Tusar <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ndreys authored and gregkh committed Sep 4, 2019
1 parent 3f72879 commit 5982199
Showing 1 changed file with 23 additions and 30 deletions.
53 changes: 23 additions & 30 deletions drivers/tty/serial/fsl_lpuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,26 @@ static void rx_dma_timer_init(struct lpuart_port *sport)
add_timer(&sport->lpuart_timer);
}

static void lpuart_tx_dma_startup(struct lpuart_port *sport)
{
u32 uartbaud;

if (sport->dma_tx_chan && !lpuart_dma_tx_request(&sport->port)) {
init_waitqueue_head(&sport->dma_wait);
sport->lpuart_dma_tx_use = true;
if (lpuart_is_32(sport)) {
uartbaud = lpuart32_read(&sport->port, UARTBAUD);
lpuart32_write(&sport->port,
uartbaud | UARTBAUD_TDMAE, UARTBAUD);
} else {
writeb(readb(sport->port.membase + UARTCR5) |
UARTCR5_TDMAS, sport->port.membase + UARTCR5);
}
} else {
sport->lpuart_dma_tx_use = false;
}
}

static int lpuart_startup(struct uart_port *port)
{
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
Expand Down Expand Up @@ -1471,14 +1491,7 @@ static int lpuart_startup(struct uart_port *port)
sport->lpuart_dma_rx_use = false;
}

if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) {
init_waitqueue_head(&sport->dma_wait);
sport->lpuart_dma_tx_use = true;
temp = readb(port->membase + UARTCR5);
writeb(temp | UARTCR5_TDMAS, port->membase + UARTCR5);
} else {
sport->lpuart_dma_tx_use = false;
}
lpuart_tx_dma_startup(sport);

spin_unlock_irqrestore(&sport->port.lock, flags);

Expand Down Expand Up @@ -1521,14 +1534,7 @@ static int lpuart32_startup(struct uart_port *port)
sport->lpuart_dma_rx_use = false;
}

if (sport->dma_tx_chan && !lpuart_dma_tx_request(port)) {
init_waitqueue_head(&sport->dma_wait);
sport->lpuart_dma_tx_use = true;
temp = lpuart32_read(&sport->port, UARTBAUD);
lpuart32_write(&sport->port, temp | UARTBAUD_TDMAE, UARTBAUD);
} else {
sport->lpuart_dma_tx_use = false;
}
lpuart_tx_dma_startup(sport);

if (sport->lpuart_dma_rx_use) {
/* RXWATER must be 0 */
Expand Down Expand Up @@ -2577,20 +2583,7 @@ static int lpuart_resume(struct device *dev)
}
}

if (sport->dma_tx_chan && !lpuart_dma_tx_request(&sport->port)) {
init_waitqueue_head(&sport->dma_wait);
sport->lpuart_dma_tx_use = true;
if (lpuart_is_32(sport)) {
temp = lpuart32_read(&sport->port, UARTBAUD);
lpuart32_write(&sport->port,
temp | UARTBAUD_TDMAE, UARTBAUD);
} else {
writeb(readb(sport->port.membase + UARTCR5) |
UARTCR5_TDMAS, sport->port.membase + UARTCR5);
}
} else {
sport->lpuart_dma_tx_use = false;
}
lpuart_tx_dma_startup(sport);

if (lpuart_is_32(sport)) {
if (sport->lpuart_dma_rx_use) {
Expand Down

0 comments on commit 5982199

Please sign in to comment.