Skip to content

Commit 9335e23

Browse files
cristiccgregkh
authored andcommitted
tty: serial: owl: Add support for kernel debugger
Implement 'poll_put_char' and 'poll_get_char' callbacks in struct 'owl_uart_ops' that enables OWL UART to be used for kernel debugging over serial line. Signed-off-by: Cristian Ciocaltea <[email protected]> Link: https://lore.kernel.org/r/026543195b9aeefb339d90abc5660a6ac7463c63.1610484108.git.cristian.ciocaltea@gmail.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c9cd57b commit 9335e23

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

drivers/tty/serial/owl-uart.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/console.h>
1313
#include <linux/delay.h>
1414
#include <linux/io.h>
15+
#include <linux/iopoll.h>
1516
#include <linux/module.h>
1617
#include <linux/of.h>
1718
#include <linux/platform_device.h>
@@ -62,6 +63,9 @@
6263
#define OWL_UART_STAT_TRFL_MASK GENMASK(16, 11)
6364
#define OWL_UART_STAT_UTBB BIT(17)
6465

66+
#define OWL_UART_POLL_USEC 5
67+
#define OWL_UART_TIMEOUT_USEC 10000
68+
6569
static struct uart_driver owl_uart_driver;
6670

6771
struct owl_uart_info {
@@ -461,6 +465,36 @@ static void owl_uart_config_port(struct uart_port *port, int flags)
461465
}
462466
}
463467

468+
#ifdef CONFIG_CONSOLE_POLL
469+
470+
static int owl_uart_poll_get_char(struct uart_port *port)
471+
{
472+
if (owl_uart_read(port, OWL_UART_STAT) & OWL_UART_STAT_RFEM)
473+
return NO_POLL_CHAR;
474+
475+
return owl_uart_read(port, OWL_UART_RXDAT);
476+
}
477+
478+
static void owl_uart_poll_put_char(struct uart_port *port, unsigned char ch)
479+
{
480+
u32 reg;
481+
int ret;
482+
483+
/* Wait while FIFO is full or timeout */
484+
ret = readl_poll_timeout_atomic(port->membase + OWL_UART_STAT, reg,
485+
!(reg & OWL_UART_STAT_TFFU),
486+
OWL_UART_POLL_USEC,
487+
OWL_UART_TIMEOUT_USEC);
488+
if (ret == -ETIMEDOUT) {
489+
dev_err(port->dev, "Timeout waiting while UART TX FULL\n");
490+
return;
491+
}
492+
493+
owl_uart_write(port, ch, OWL_UART_TXDAT);
494+
}
495+
496+
#endif /* CONFIG_CONSOLE_POLL */
497+
464498
static const struct uart_ops owl_uart_ops = {
465499
.set_mctrl = owl_uart_set_mctrl,
466500
.get_mctrl = owl_uart_get_mctrl,
@@ -476,6 +510,10 @@ static const struct uart_ops owl_uart_ops = {
476510
.request_port = owl_uart_request_port,
477511
.release_port = owl_uart_release_port,
478512
.verify_port = owl_uart_verify_port,
513+
#ifdef CONFIG_CONSOLE_POLL
514+
.poll_get_char = owl_uart_poll_get_char,
515+
.poll_put_char = owl_uart_poll_put_char,
516+
#endif
479517
};
480518

481519
#ifdef CONFIG_SERIAL_OWL_CONSOLE

0 commit comments

Comments
 (0)