* [PATCH] serial: ar933x: Add polling support
@ 2025-10-01 11:47 Sven Eckelmann
2025-10-01 12:07 ` Sven Eckelmann
0 siblings, 1 reply; 2+ messages in thread
From: Sven Eckelmann @ 2025-10-01 11:47 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-kernel, linux-serial, Sven Eckelmann
KGDB requires at least the polling hooks .poll_get_char and .poll_put_char
to transmit/receive character via the serial driver.
Signed-off-by: Sven Eckelmann <se@simonwunderlich.de>
---
drivers/tty/serial/ar933x_uart.c | 62 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/drivers/tty/serial/ar933x_uart.c b/drivers/tty/serial/ar933x_uart.c
index 8bb33556b31208a1707ca7a48db0aa2ca81452bd..5b491db9d2fc01e051f629f224024ac4dc4d35ff 100644
--- a/drivers/tty/serial/ar933x_uart.c
+++ b/drivers/tty/serial/ar933x_uart.c
@@ -560,6 +560,64 @@ static int ar933x_uart_verify_port(struct uart_port *port,
return 0;
}
+#ifdef CONFIG_CONSOLE_POLL
+static int ar933x_poll_get_char(struct uart_port *port)
+{
+ struct ar933x_uart_port *up =
+ container_of(port, struct ar933x_uart_port, port);
+ unsigned int rdata;
+ unsigned char ch;
+ u32 imr;
+
+ /* Disable all interrupts */
+ imr = ar933x_uart_read(up, AR933X_UART_INT_EN_REG);
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, 0);
+
+ rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG);
+ if ((rdata & AR933X_UART_DATA_RX_CSR) == 0) {
+ /* Enable interrupts */
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, imr);
+ return NO_POLL_CHAR;
+ }
+
+ /* remove the character from the FIFO */
+ ar933x_uart_write(up, AR933X_UART_DATA_REG,
+ AR933X_UART_DATA_RX_CSR);
+
+ ch = rdata & AR933X_UART_DATA_TX_RX_MASK;
+
+ /* Enable interrupts */
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, imr);
+
+ return ch;
+}
+
+static void ar933x_poll_put_char(struct uart_port *port, unsigned char c)
+{
+ struct ar933x_uart_port *up =
+ container_of(port, struct ar933x_uart_port, port);
+ u32 imr;
+
+ /* Disable all interrupts */
+ imr = ar933x_uart_read(up, AR933X_UART_INT_EN_REG);
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, 0);
+
+ /* Wait until FIFO is empty */
+ while (!(ar933x_uart_read(up, AR933X_UART_DATA_REG) & AR933X_UART_DATA_TX_CSR))
+ cpu_relax();
+
+ /* Write a character */
+ ar933x_uart_putc(up, c);
+
+ /* Wait until FIFO is empty */
+ while (!(ar933x_uart_read(up, AR933X_UART_DATA_REG) & AR933X_UART_DATA_TX_CSR))
+ cpu_relax();
+
+ /* Enable interrupts */
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, imr);
+}
+#endif
+
static const struct uart_ops ar933x_uart_ops = {
.tx_empty = ar933x_uart_tx_empty,
.set_mctrl = ar933x_uart_set_mctrl,
@@ -576,6 +634,10 @@ static const struct uart_ops ar933x_uart_ops = {
.request_port = ar933x_uart_request_port,
.config_port = ar933x_uart_config_port,
.verify_port = ar933x_uart_verify_port,
+#ifdef CONFIG_CONSOLE_POLL
+ .poll_get_char = ar933x_poll_get_char,
+ .poll_put_char = ar933x_poll_put_char,
+#endif
};
static int ar933x_config_rs485(struct uart_port *port, struct ktermios *termios,
---
base-commit: f83ec76bf285bea5727f478a68b894f5543ca76e
change-id: 20251001-ar933x-kgdb-support-25f5451b2a59
Best regards,
--
Sven Eckelmann <se@simonwunderlich.de>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] serial: ar933x: Add polling support
2025-10-01 11:47 [PATCH] serial: ar933x: Add polling support Sven Eckelmann
@ 2025-10-01 12:07 ` Sven Eckelmann
0 siblings, 0 replies; 2+ messages in thread
From: Sven Eckelmann @ 2025-10-01 12:07 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby; +Cc: linux-kernel, linux-serial
[-- Attachment #1.1: Type: text/plain, Size: 1059 bytes --]
On Wednesday, 1 October 2025 13:47:26 CEST Sven Eckelmann wrote:
> KGDB requires at least the polling hooks .poll_get_char and .poll_put_char
> to transmit/receive character via the serial driver.
>
> Signed-off-by: Sven Eckelmann <se@simonwunderlich.de>
> ---
> drivers/tty/serial/ar933x_uart.c | 62 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 62 insertions(+)
I also had a look at break detection to ease the debugging on our side. Just
to be able to switch to KGDB mode via gdb.
While I got it working, it is more a hack than a good implementation. I've
attached the hack in case someone wants to continue to work on it.
On Wednesday, 1 October 2025 14:05:41 CEST Greg Kroah-Hartman wrote:
> Right now, the development tree you have sent a patch for is "closed"
> due to the timing of the merge window. Don't worry, the patch(es) you
> have sent are not lost, and will be looked at after the merge window is
> over (after the -rc1 kernel is released by Linus).
*looks at the calendar* Oh, yes, there was something.
Regards,
Sven
[-- Attachment #1.2: RFC-0001-serial-ar933x-Handle-break-events.patch --]
[-- Type: text/x-patch, Size: 3956 bytes --]
From 7892ef568d7ca4c1c2a0ed9fb8edbadfe8e70177 Mon Sep 17 00:00:00 2001
From: Sven Eckelmann <se@simonwunderlich.de>
Date: Mon, 15 Sep 2025 15:35:14 +0200
Subject: [PATCH RFC] serial: ar933x: Handle break events
Signed-off-by: Sven Eckelmann <se@simonwunderlich.de>
---
drivers/tty/serial/ar933x_uart.c | 53 ++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/tty/serial/ar933x_uart.c b/drivers/tty/serial/ar933x_uart.c
index 5b491db9d2fc..bc0a63e4934b 100644
--- a/drivers/tty/serial/ar933x_uart.c
+++ b/drivers/tty/serial/ar933x_uart.c
@@ -105,6 +105,30 @@ static inline void ar933x_uart_stop_tx_interrupt(struct ar933x_uart_port *up)
ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
}
+static inline void ar933x_uart_start_rxbreak_on_interrupt(struct ar933x_uart_port *up)
+{
+ up->ier |= AR933X_UART_INT_RX_BREAK_ON;
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
+}
+
+static inline void ar933x_uart_stop_rxbreak_on_interrupt(struct ar933x_uart_port *up)
+{
+ up->ier &= ~AR933X_UART_INT_RX_BREAK_ON;
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
+}
+
+static inline void ar933x_uart_start_rxbreak_off_interrupt(struct ar933x_uart_port *up)
+{
+ up->ier |= AR933X_UART_INT_RX_BREAK_OFF;
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
+}
+
+static inline void ar933x_uart_stop_rxbreak_off_interrupt(struct ar933x_uart_port *up)
+{
+ up->ier &= ~AR933X_UART_INT_RX_BREAK_OFF;
+ ar933x_uart_write(up, AR933X_UART_INT_EN_REG, up->ier);
+}
+
static inline void ar933x_uart_start_rx_interrupt(struct ar933x_uart_port *up)
{
up->ier |= AR933X_UART_INT_RX_VALID;
@@ -212,6 +236,7 @@ static void ar933x_uart_stop_rx(struct uart_port *port)
container_of(port, struct ar933x_uart_port, port);
ar933x_uart_stop_rx_interrupt(up);
+ ar933x_uart_stop_rxbreak_on_interrupt(up);
}
static void ar933x_uart_break_ctl(struct uart_port *port, int break_state)
@@ -444,11 +469,14 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id)
{
struct ar933x_uart_port *up = dev_id;
unsigned int status;
+ bool is_break;
status = ar933x_uart_read(up, AR933X_UART_CS_REG);
if ((status & AR933X_UART_CS_HOST_INT) == 0)
return IRQ_NONE;
+ is_break = status & AR933X_UART_CS_RX_BREAK;
+
uart_port_lock(&up->port);
status = ar933x_uart_read(up, AR933X_UART_INT_REG);
@@ -467,6 +495,29 @@ static irqreturn_t ar933x_uart_interrupt(int irq, void *dev_id)
ar933x_uart_tx_chars(up);
}
+ if (status & AR933X_UART_INT_RX_BREAK_ON)
+ ar933x_uart_write(up, AR933X_UART_INT_REG,
+ AR933X_UART_INT_RX_BREAK_ON);
+
+ if (status & AR933X_UART_INT_RX_BREAK_OFF)
+ ar933x_uart_write(up, AR933X_UART_INT_REG,
+ AR933X_UART_INT_RX_BREAK_OFF);
+
+ if (is_break) {
+ /* disable "active break" interrupt */
+ ar933x_uart_stop_rxbreak_on_interrupt(up);
+ ar933x_uart_start_rxbreak_off_interrupt(up);
+
+ /* inform serial core about break */
+ up->port.icount.brk++;
+ if (!up->port.sysrq)
+ uart_handle_break(&up->port);
+ } else if (!(up->ier & AR933X_UART_INT_RX_BREAK_ON)) {
+ /* enable "active break" interrupt */
+ ar933x_uart_start_rxbreak_on_interrupt(up);
+ ar933x_uart_stop_rxbreak_off_interrupt(up);
+ }
+
uart_unlock_and_check_sysrq(&up->port);
return IRQ_HANDLED;
@@ -496,6 +547,7 @@ static int ar933x_uart_startup(struct uart_port *port)
/* Enable RX interrupts */
ar933x_uart_start_rx_interrupt(up);
+ ar933x_uart_start_rxbreak_on_interrupt(up);
uart_port_unlock_irqrestore(&up->port, flags);
@@ -829,6 +881,7 @@ static int ar933x_uart_probe(struct platform_device *pdev)
port->ops = &ar933x_uart_ops;
port->rs485_config = ar933x_config_rs485;
port->rs485_supported = ar933x_rs485_supported;
+ port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_AR933X_CONSOLE);
baud = ar933x_uart_get_baud(port->uartclk, AR933X_UART_MAX_SCALE, 1);
up->min_baud = max_t(unsigned int, baud, AR933X_UART_MIN_BAUD);
--
2.47.3
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-01 12:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01 11:47 [PATCH] serial: ar933x: Add polling support Sven Eckelmann
2025-10-01 12:07 ` Sven Eckelmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox