* [PATCH V2 0/3] serial: stm32: add earlycon and polling mode
@ 2022-04-08 12:26 Valentin Caron
2022-04-08 12:26 ` [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Valentin Caron @ 2022-04-08 12:26 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.
Changes since v1:
- Fix warning "unused variable 'ret'"
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 | 100 +++++++++++++++++-
drivers/tty/serial/stm32-usart.h | 2 +
4 files changed, 104 insertions(+), 5 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function
2022-04-08 12:26 [PATCH V2 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
@ 2022-04-08 12:26 ` Valentin Caron
2022-04-08 12:26 ` [PATCH V2 2/3] serial: stm32: add KGDB support Valentin Caron
2022-04-08 12:26 ` [PATCH V2 3/3] serial: stm32: add earlycon support Valentin Caron
2 siblings, 0 replies; 7+ messages in thread
From: Valentin Caron @ 2022-04-08 12:26 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] 7+ messages in thread
* [PATCH V2 2/3] serial: stm32: add KGDB support
2022-04-08 12:26 [PATCH V2 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-08 12:26 ` [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
@ 2022-04-08 12:26 ` Valentin Caron
2022-04-08 12:26 ` [PATCH V2 3/3] serial: stm32: add earlycon support Valentin Caron
2 siblings, 0 replies; 7+ messages in thread
From: Valentin Caron @ 2022-04-08 12:26 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 | 37 ++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index 83895da84891..4307c822afe4 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,33 @@ 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;
+
+ 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 +1271,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 +1673,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 +1690,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] 7+ messages in thread
* [PATCH V2 3/3] serial: stm32: add earlycon support
2022-04-08 12:26 [PATCH V2 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-08 12:26 ` [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
2022-04-08 12:26 ` [PATCH V2 2/3] serial: stm32: add KGDB support Valentin Caron
@ 2022-04-08 12:26 ` Valentin Caron
2022-04-11 14:59 ` Geert Uytterhoeven
2 siblings, 1 reply; 7+ messages in thread
From: Valentin Caron @ 2022-04-08 12:26 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 4307c822afe4..65988e6efaa2 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1766,6 +1766,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] 7+ messages in thread
* Re: [PATCH V2 3/3] serial: stm32: add earlycon support
2022-04-08 12:26 ` [PATCH V2 3/3] serial: stm32: add earlycon support Valentin Caron
@ 2022-04-11 14:59 ` Geert Uytterhoeven
2022-04-14 12:17 ` Valentin CARON
0 siblings, 1 reply; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-04-11 14:59 UTC (permalink / raw)
To: Valentin Caron
Cc: Greg Kroah-Hartman, Jonathan Corbet, Jiri Slaby, Maxime Coquelin,
Alexandre Torgue, Erwan Le Ray, open list:SERIAL DRIVERS,
linux-stm32, Linux ARM, Linux Kernel Mailing List,
open list:DOCUMENTATION
Hi Valentin,
On Fri, Apr 8, 2022 at 3:14 PM Valentin Caron
<valentin.caron@foss.st.com> wrote:
> 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>
Thanks for your patch!
> --- 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.
Why do you need this parameter?
Given this driver uses DT, can't it figure out the serial port address
from chosen/stdout-path?
+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);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 3/3] serial: stm32: add earlycon support
2022-04-11 14:59 ` Geert Uytterhoeven
@ 2022-04-14 12:17 ` Valentin CARON
2022-04-14 12:24 ` Geert Uytterhoeven
0 siblings, 1 reply; 7+ messages in thread
From: Valentin CARON @ 2022-04-14 12:17 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Greg Kroah-Hartman, Jonathan Corbet, Jiri Slaby, Maxime Coquelin,
Alexandre Torgue, Erwan Le Ray, open list:SERIAL DRIVERS,
linux-stm32, Linux ARM, Linux Kernel Mailing List,
open list:DOCUMENTATION
On 4/11/22 16:59, Geert Uytterhoeven wrote:
> Hi Valentin,
>
> On Fri, Apr 8, 2022 at 3:14 PM Valentin Caron
> <valentin.caron@foss.st.com> wrote:
>> 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>
> Thanks for your patch!
>
>> --- 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.
> Why do you need this parameter?
>
> Given this driver uses DT, can't it figure out the serial port address
> from chosen/stdout-path?
>
> +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);
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
> -- Linus Torvalds
Hi Geert,
I took the example of other serial drivers.
Both methods work (with earlycon/stdout-path and with
earlycon=stm32,0xXXXXXXX)
but your right, the second will probably never used on this driver.
Should I remove it ?
Thanks,
Valentin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2 3/3] serial: stm32: add earlycon support
2022-04-14 12:17 ` Valentin CARON
@ 2022-04-14 12:24 ` Geert Uytterhoeven
0 siblings, 0 replies; 7+ messages in thread
From: Geert Uytterhoeven @ 2022-04-14 12:24 UTC (permalink / raw)
To: Valentin CARON
Cc: Greg Kroah-Hartman, Jonathan Corbet, Jiri Slaby, Maxime Coquelin,
Alexandre Torgue, Erwan Le Ray, open list:SERIAL DRIVERS,
linux-stm32, Linux ARM, Linux Kernel Mailing List,
open list:DOCUMENTATION
Hi Valentin,
On Thu, Apr 14, 2022 at 2:17 PM Valentin CARON
<valentin.caron@foss.st.com> wrote:
> On 4/11/22 16:59, Geert Uytterhoeven wrote:
> > On Fri, Apr 8, 2022 at 3:14 PM Valentin Caron
> > <valentin.caron@foss.st.com> wrote:
> >> 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>
> > Thanks for your patch!
> >
> >> --- 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.
> > Why do you need this parameter?
> >
> > Given this driver uses DT, can't it figure out the serial port address
> > from chosen/stdout-path?
>
> I took the example of other serial drivers.
> Both methods work (with earlycon/stdout-path and with
> earlycon=stm32,0xXXXXXXX)
> but your right, the second will probably never used on this driver.
>
> Should I remove it ?
I think you should. The less platform-specific kernel parameters,
the better. And the less bad examples to copy from.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-14 12:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08 12:26 [PATCH V2 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-08 12:26 ` [PATCH V2 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
2022-04-08 12:26 ` [PATCH V2 2/3] serial: stm32: add KGDB support Valentin Caron
2022-04-08 12:26 ` [PATCH V2 3/3] serial: stm32: add earlycon support Valentin Caron
2022-04-11 14:59 ` Geert Uytterhoeven
2022-04-14 12:17 ` Valentin CARON
2022-04-14 12:24 ` Geert Uytterhoeven
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).