Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <cristian.ciocaltea@gmail.com>
Link: https://lore.kernel.org/r/026543195b9aeefb339d90abc5660a6ac7463c63.1610484108.git.cristian.ciocaltea@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Cristian Ciocaltea and committed by
Greg Kroah-Hartman
9335e23d c9cd57bf

+38
+38
drivers/tty/serial/owl-uart.c
··· 12 12 #include <linux/console.h> 13 13 #include <linux/delay.h> 14 14 #include <linux/io.h> 15 + #include <linux/iopoll.h> 15 16 #include <linux/module.h> 16 17 #include <linux/of.h> 17 18 #include <linux/platform_device.h> ··· 62 61 #define OWL_UART_STAT_TFES BIT(10) 63 62 #define OWL_UART_STAT_TRFL_MASK GENMASK(16, 11) 64 63 #define OWL_UART_STAT_UTBB BIT(17) 64 + 65 + #define OWL_UART_POLL_USEC 5 66 + #define OWL_UART_TIMEOUT_USEC 10000 65 67 66 68 static struct uart_driver owl_uart_driver; 67 69 ··· 465 461 } 466 462 } 467 463 464 + #ifdef CONFIG_CONSOLE_POLL 465 + 466 + static int owl_uart_poll_get_char(struct uart_port *port) 467 + { 468 + if (owl_uart_read(port, OWL_UART_STAT) & OWL_UART_STAT_RFEM) 469 + return NO_POLL_CHAR; 470 + 471 + return owl_uart_read(port, OWL_UART_RXDAT); 472 + } 473 + 474 + static void owl_uart_poll_put_char(struct uart_port *port, unsigned char ch) 475 + { 476 + u32 reg; 477 + int ret; 478 + 479 + /* Wait while FIFO is full or timeout */ 480 + ret = readl_poll_timeout_atomic(port->membase + OWL_UART_STAT, reg, 481 + !(reg & OWL_UART_STAT_TFFU), 482 + OWL_UART_POLL_USEC, 483 + OWL_UART_TIMEOUT_USEC); 484 + if (ret == -ETIMEDOUT) { 485 + dev_err(port->dev, "Timeout waiting while UART TX FULL\n"); 486 + return; 487 + } 488 + 489 + owl_uart_write(port, ch, OWL_UART_TXDAT); 490 + } 491 + 492 + #endif /* CONFIG_CONSOLE_POLL */ 493 + 468 494 static const struct uart_ops owl_uart_ops = { 469 495 .set_mctrl = owl_uart_set_mctrl, 470 496 .get_mctrl = owl_uart_get_mctrl, ··· 510 476 .request_port = owl_uart_request_port, 511 477 .release_port = owl_uart_release_port, 512 478 .verify_port = owl_uart_verify_port, 479 + #ifdef CONFIG_CONSOLE_POLL 480 + .poll_get_char = owl_uart_poll_get_char, 481 + .poll_put_char = owl_uart_poll_put_char, 482 + #endif 513 483 }; 514 484 515 485 #ifdef CONFIG_SERIAL_OWL_CONSOLE