* [PATCH 0/3] serial: stm32: add earlycon and polling mode
@ 2022-04-07 12:31 Valentin Caron
2022-04-07 12:31 ` [PATCH 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Valentin Caron @ 2022-04-07 12:31 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jonathan Corbet
Cc: Jiri Slaby, Maxime Coquelin, Alexandre Torgue, Erwan Le Ray,
Valentin Caron, linux-serial, linux-stm32, linux-arm-kernel,
linux-kernel, linux-doc
- Add support of early console and polling mode in stm32-usart driver.
- Avoid a possible infinite loop in putchar function.
Valentin Caron (3):
serial: stm32: remove infinite loop possibility in putchar function
serial: stm32: add KGDB support
serial: stm32: add earlycon support
.../admin-guide/kernel-parameters.txt | 6 ++
drivers/tty/serial/Kconfig | 1 +
drivers/tty/serial/stm32-usart.c | 101 +++++++++++++++++-
drivers/tty/serial/stm32-usart.h | 2 +
4 files changed, 105 insertions(+), 5 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] serial: stm32: remove infinite loop possibility in putchar function
2022-04-07 12:31 [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
@ 2022-04-07 12:31 ` Valentin Caron
2022-04-07 12:31 ` [PATCH 2/3] serial: stm32: add KGDB support Valentin Caron
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Valentin Caron @ 2022-04-07 12:31 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jonathan Corbet
Cc: Jiri Slaby, Maxime Coquelin, Alexandre Torgue, Erwan Le Ray,
Valentin Caron, linux-serial, linux-stm32, linux-arm-kernel,
linux-kernel, linux-doc
Rework stm32_usart_console_putchar() function in order to anticipate
the case where the character can never be sent.
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
drivers/tty/serial/stm32-usart.c | 12 +++++++++---
drivers/tty/serial/stm32-usart.h | 2 ++
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 87b5cd4c9743..83895da84891 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1645,10 +1645,16 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch
{
struct stm32_port *stm32_port = to_stm32_port(port);
const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
+ u32 isr;
+ int ret;
- while (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_TXE))
- cpu_relax();
-
+ ret = readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, isr,
+ (isr & USART_SR_TXE), 100,
+ STM32_USART_TIMEOUT_USEC);
+ if (ret != 0) {
+ dev_err(port->dev, "Error while sending data in UART TX : %d\n", ret);
+ return;
+ }
writel_relaxed(ch, port->membase + ofs->tdr);
}
diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h
index feab952aec16..d734c4a5fd24 100644
--- a/drivers/tty/serial/stm32-usart.h
+++ b/drivers/tty/serial/stm32-usart.h
@@ -251,6 +251,8 @@ struct stm32_usart_info stm32h7_info = {
#define RX_BUF_P (RX_BUF_L / 2) /* dma rx buffer period */
#define TX_BUF_L RX_BUF_L /* dma tx buffer length */
+#define STM32_USART_TIMEOUT_USEC USEC_PER_SEC /* 1s timeout in µs */
+
struct stm32_port {
struct uart_port port;
struct clk *clk;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] serial: stm32: add KGDB support
2022-04-07 12:31 [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-07 12:31 ` [PATCH 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
@ 2022-04-07 12:31 ` Valentin Caron
2022-04-07 12:31 ` [PATCH 3/3] serial: stm32: add earlycon support Valentin Caron
2022-04-08 12:34 ` [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin CARON
3 siblings, 0 replies; 5+ messages in thread
From: Valentin Caron @ 2022-04-07 12:31 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jonathan Corbet
Cc: Jiri Slaby, Maxime Coquelin, Alexandre Torgue, Erwan Le Ray,
Valentin Caron, linux-serial, linux-stm32, linux-arm-kernel,
linux-kernel, linux-doc
Add support for KGDB in stm32 serial driver by implementing characters
polling callbacks (poll_init, poll_get_char and poll_put_char).
Signed-off-by: Erwan Le Ray <erwan.leray@foss.st.com>
Signed-off-by: Jean Philippe Romain <jean-philippe.romain@foss.st.com>
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
drivers/tty/serial/stm32-usart.c | 38 ++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 83895da84891..d2cf789c7997 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -37,6 +37,7 @@
static void stm32_usart_stop_tx(struct uart_port *port);
static void stm32_usart_transmit_chars(struct uart_port *port);
+static void __maybe_unused stm32_usart_console_putchar(struct uart_port *port, unsigned char ch);
static inline struct stm32_port *to_stm32_port(struct uart_port *port)
{
@@ -1222,6 +1223,34 @@ static void stm32_usart_pm(struct uart_port *port, unsigned int state,
}
}
+#if defined(CONFIG_CONSOLE_POLL)
+
+ /* Callbacks for characters polling in debug context (i.e. KGDB). */
+static int stm32_usart_poll_init(struct uart_port *port)
+{
+ struct stm32_port *stm32_port = to_stm32_port(port);
+
+ return clk_prepare_enable(stm32_port->clk);
+}
+
+static int stm32_usart_poll_get_char(struct uart_port *port)
+{
+ struct stm32_port *stm32_port = to_stm32_port(port);
+ const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
+ unsigned int ret;
+
+ if (!(readl_relaxed(port->membase + ofs->isr) & USART_SR_RXNE))
+ return NO_POLL_CHAR;
+
+ return readl_relaxed(port->membase + ofs->rdr) & stm32_port->rdr_mask;
+}
+
+static void stm32_usart_poll_put_char(struct uart_port *port, unsigned char ch)
+{
+ stm32_usart_console_putchar(port, ch);
+}
+#endif /* CONFIG_CONSOLE_POLL */
+
static const struct uart_ops stm32_uart_ops = {
.tx_empty = stm32_usart_tx_empty,
.set_mctrl = stm32_usart_set_mctrl,
@@ -1243,6 +1272,11 @@ static const struct uart_ops stm32_uart_ops = {
.request_port = stm32_usart_request_port,
.config_port = stm32_usart_config_port,
.verify_port = stm32_usart_verify_port,
+#if defined(CONFIG_CONSOLE_POLL)
+ .poll_init = stm32_usart_poll_init,
+ .poll_get_char = stm32_usart_poll_get_char,
+ .poll_put_char = stm32_usart_poll_put_char,
+#endif /* CONFIG_CONSOLE_POLL */
};
/*
@@ -1640,8 +1674,7 @@ static int stm32_usart_serial_remove(struct platform_device *pdev)
return 0;
}
-#ifdef CONFIG_SERIAL_STM32_CONSOLE
-static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch)
+static void __maybe_unused stm32_usart_console_putchar(struct uart_port *port, unsigned char ch)
{
struct stm32_port *stm32_port = to_stm32_port(port);
const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs;
@@ -1658,6 +1691,7 @@ static void stm32_usart_console_putchar(struct uart_port *port, unsigned char ch
writel_relaxed(ch, port->membase + ofs->tdr);
}
+#ifdef CONFIG_SERIAL_STM32_CONSOLE
static void stm32_usart_console_write(struct console *co, const char *s,
unsigned int cnt)
{
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] serial: stm32: add earlycon support
2022-04-07 12:31 [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-07 12:31 ` [PATCH 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
2022-04-07 12:31 ` [PATCH 2/3] serial: stm32: add KGDB support Valentin Caron
@ 2022-04-07 12:31 ` Valentin Caron
2022-04-08 12:34 ` [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin CARON
3 siblings, 0 replies; 5+ messages in thread
From: Valentin Caron @ 2022-04-07 12:31 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jonathan Corbet
Cc: Jiri Slaby, Maxime Coquelin, Alexandre Torgue, Erwan Le Ray,
Valentin Caron, linux-serial, linux-stm32, linux-arm-kernel,
linux-kernel, linux-doc
Add early console support in stm32 uart driver.
Signed-off-by: Alexandre Torgue <alexandre.torgue@foss.st.com>
Signed-off-by: Valentin Caron <valentin.caron@foss.st.com>
---
.../admin-guide/kernel-parameters.txt | 6 +++
drivers/tty/serial/Kconfig | 1 +
drivers/tty/serial/stm32-usart.c | 51 +++++++++++++++++++
3 files changed, 58 insertions(+)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 3f1cc5e317ed..e941c3351c7a 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -1264,6 +1264,12 @@
address must be provided, and the serial port must
already be setup and configured.
+ stm32,<addr>
+ Use early console provided by ST Microelectronics
+ serial driver for STM32 SoCs. A valid base address
+ must be provided, and the serial port must already
+ be setup and configured.
+
earlyprintk= [X86,SH,ARM,M68k,S390]
earlyprintk=vga
earlyprintk=sclp
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 6949e883ffab..ed59de8d2e11 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -1443,6 +1443,7 @@ config SERIAL_STM32_CONSOLE
bool "Support for console on STM32"
depends on SERIAL_STM32=y
select SERIAL_CORE_CONSOLE
+ select SERIAL_EARLYCON
config SERIAL_MVEBU_UART
bool "Marvell EBU serial port support"
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index d2cf789c7997..b6852a5a9143 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1767,6 +1767,57 @@ static struct console stm32_console = {
#define STM32_SERIAL_CONSOLE NULL
#endif /* CONFIG_SERIAL_STM32_CONSOLE */
+#ifdef CONFIG_SERIAL_EARLYCON
+static void early_stm32_usart_console_putchar(struct uart_port *port, unsigned char ch)
+{
+ struct stm32_usart_info *info = port->private_data;
+
+ while (!(readl_relaxed(port->membase + info->ofs.isr) & USART_SR_TXE))
+ cpu_relax();
+
+ writel_relaxed(ch, port->membase + info->ofs.tdr);
+}
+
+static void early_stm32_serial_write(struct console *console, const char *s, unsigned int count)
+{
+ struct earlycon_device *device = console->data;
+ struct uart_port *port = &device->port;
+
+ uart_console_write(port, s, count, early_stm32_usart_console_putchar);
+}
+
+static int __init early_stm32_h7_serial_setup(struct earlycon_device *device, const char *options)
+{
+ if (!(device->port.membase || device->port.iobase))
+ return -ENODEV;
+ device->port.private_data = &stm32h7_info;
+ device->con->write = early_stm32_serial_write;
+ return 0;
+}
+
+static int __init early_stm32_f7_serial_setup(struct earlycon_device *device, const char *options)
+{
+ if (!(device->port.membase || device->port.iobase))
+ return -ENODEV;
+ device->port.private_data = &stm32f7_info;
+ device->con->write = early_stm32_serial_write;
+ return 0;
+}
+
+static int __init early_stm32_f4_serial_setup(struct earlycon_device *device, const char *options)
+{
+ if (!(device->port.membase || device->port.iobase))
+ return -ENODEV;
+ device->port.private_data = &stm32f4_info;
+ device->con->write = early_stm32_serial_write;
+ return 0;
+}
+
+OF_EARLYCON_DECLARE(stm32, "st,stm32h7-uart", early_stm32_h7_serial_setup);
+OF_EARLYCON_DECLARE(stm32, "st,stm32f7-uart", early_stm32_f7_serial_setup);
+OF_EARLYCON_DECLARE(stm32, "st,stm32-uart", early_stm32_f4_serial_setup);
+#endif /* CONFIG_SERIAL_EARLYCON */
+
static struct uart_driver stm32_usart_driver = {
.driver_name = DRIVER_NAME,
.dev_name = STM32_SERIAL_NAME,
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] serial: stm32: add earlycon and polling mode
2022-04-07 12:31 [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
` (2 preceding siblings ...)
2022-04-07 12:31 ` [PATCH 3/3] serial: stm32: add earlycon support Valentin Caron
@ 2022-04-08 12:34 ` Valentin CARON
3 siblings, 0 replies; 5+ messages in thread
From: Valentin CARON @ 2022-04-08 12:34 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jonathan Corbet
Cc: Jiri Slaby, Maxime Coquelin, Alexandre Torgue, Erwan Le Ray,
linux-serial, linux-stm32, linux-arm-kernel, linux-kernel,
linux-doc
On 4/7/22 14:31, Valentin Caron wrote:
> - Add support of early console and polling mode in stm32-usart driver.
> - Avoid a possible infinite loop in putchar function.
>
> Valentin Caron (3):
> serial: stm32: remove infinite loop possibility in putchar function
> serial: stm32: add KGDB support
> serial: stm32: add earlycon support
>
> .../admin-guide/kernel-parameters.txt | 6 ++
> drivers/tty/serial/Kconfig | 1 +
> drivers/tty/serial/stm32-usart.c | 101 +++++++++++++++++-
> drivers/tty/serial/stm32-usart.h | 2 +
> 4 files changed, 105 insertions(+), 5 deletions(-)
>
Hi,
Please drop this series, I sent a V2
Thanks,
Valentin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-08 12:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 12:31 [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-07 12:31 ` [PATCH 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
2022-04-07 12:31 ` [PATCH 2/3] serial: stm32: add KGDB support Valentin Caron
2022-04-07 12:31 ` [PATCH 3/3] serial: stm32: add earlycon support Valentin Caron
2022-04-08 12:34 ` [PATCH 0/3] serial: stm32: add earlycon and polling mode Valentin CARON
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).