Skip to content

Commit

Permalink
serial: bcm63xx-uart: add polling support
Browse files Browse the repository at this point in the history
The tty framework can support polling console to allow operation
in situations where interrupts are turned off. Adding polling mode
support allows using KGDB over serial console,

Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Link: https://lore.kernel.org/r/20230322223956.84647-1-arend.vanspriel@broadcom.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Arend van Spriel authored and Greg Kroah-Hartman committed Mar 29, 2023
1 parent f1d81e3 commit 945de8b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions drivers/tty/serial/bcm63xx_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,40 @@ static int bcm_uart_verify_port(struct uart_port *port,
return 0;
}

#ifdef CONFIG_CONSOLE_POLL
/*
* return true when outstanding tx equals fifo size
*/
static bool bcm_uart_tx_full(struct uart_port *port)
{
unsigned int val;

val = bcm_uart_readl(port, UART_MCTL_REG);
val = (val & UART_MCTL_TXFIFOFILL_MASK) >> UART_MCTL_TXFIFOFILL_SHIFT;
return !(port->fifosize - val);
}

static int bcm_uart_poll_get_char(struct uart_port *port)
{
unsigned int iestat;

iestat = bcm_uart_readl(port, UART_IR_REG);
if (!(iestat & UART_IR_STAT(UART_IR_RXNOTEMPTY)))
return NO_POLL_CHAR;

return bcm_uart_readl(port, UART_FIFO_REG);
}

static void bcm_uart_poll_put_char(struct uart_port *port, unsigned char c)
{
while (bcm_uart_tx_full(port)) {
cpu_relax();
}

bcm_uart_writel(port, c, UART_FIFO_REG);
}
#endif

/* serial core callbacks */
static const struct uart_ops bcm_uart_ops = {
.tx_empty = bcm_uart_tx_empty,
Expand All @@ -614,6 +648,10 @@ static const struct uart_ops bcm_uart_ops = {
.request_port = bcm_uart_request_port,
.config_port = bcm_uart_config_port,
.verify_port = bcm_uart_verify_port,
#ifdef CONFIG_CONSOLE_POLL
.poll_get_char = bcm_uart_poll_get_char,
.poll_put_char = bcm_uart_poll_put_char,
#endif
};


Expand Down

0 comments on commit 945de8b

Please sign in to comment.