All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/3] serial: stm32: add earlycon and polling mode
@ 2022-04-19  8:53 ` Valentin Caron
  0 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

- Add support of early console and polling mode in stm32-usart driver.
- Avoid a possible infinite loop in putchar function.

Changes since v2:
- Do not add "stm32" parameter in kernel-parameters.txt 

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

 drivers/tty/serial/Kconfig       |   1 +
 drivers/tty/serial/stm32-usart.c | 100 +++++++++++++++++++++++++++++--
 drivers/tty/serial/stm32-usart.h |   2 +
 3 files changed, 98 insertions(+), 5 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH V3 0/3] serial: stm32: add earlycon and polling mode
@ 2022-04-19  8:53 ` Valentin Caron
  0 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

- Add support of early console and polling mode in stm32-usart driver.
- Avoid a possible infinite loop in putchar function.

Changes since v2:
- Do not add "stm32" parameter in kernel-parameters.txt 

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

 drivers/tty/serial/Kconfig       |   1 +
 drivers/tty/serial/stm32-usart.c | 100 +++++++++++++++++++++++++++++--
 drivers/tty/serial/stm32-usart.h |   2 +
 3 files changed, 98 insertions(+), 5 deletions(-)

-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function
  2022-04-19  8:53 ` Valentin Caron
@ 2022-04-19  8:53   ` Valentin Caron
  -1 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

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 f886976daef6..9910a18779af 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1640,10 +1640,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] 12+ messages in thread

* [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function
@ 2022-04-19  8:53   ` Valentin Caron
  0 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

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 f886976daef6..9910a18779af 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1640,10 +1640,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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH V3 2/3] serial: stm32: add KGDB support
  2022-04-19  8:53 ` Valentin Caron
@ 2022-04-19  8:53   ` Valentin Caron
  -1 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

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 9910a18779af..8aefb286bd88 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)
 {
@@ -1217,6 +1218,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,
@@ -1238,6 +1266,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 */
 };
 
 /*
@@ -1635,8 +1668,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;
@@ -1653,6 +1685,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] 12+ messages in thread

* [PATCH V3 2/3] serial: stm32: add KGDB support
@ 2022-04-19  8:53   ` Valentin Caron
  0 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

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 9910a18779af..8aefb286bd88 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)
 {
@@ -1217,6 +1218,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,
@@ -1238,6 +1266,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 */
 };
 
 /*
@@ -1635,8 +1668,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;
@@ -1653,6 +1685,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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH V3 3/3] serial: stm32: add earlycon support
  2022-04-19  8:53 ` Valentin Caron
@ 2022-04-19  8:53   ` Valentin Caron
  -1 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

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>
---
 drivers/tty/serial/Kconfig       |  1 +
 drivers/tty/serial/stm32-usart.c | 51 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

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 8aefb286bd88..f75691e72729 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1761,6 +1761,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] 12+ messages in thread

* [PATCH V3 3/3] serial: stm32: add earlycon support
@ 2022-04-19  8:53   ` Valentin Caron
  0 siblings, 0 replies; 12+ messages in thread
From: Valentin Caron @ 2022-04-19  8:53 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Geert Uytterhoeven, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, Valentin Caron, linux-serial, linux-stm32,
	linux-arm-kernel, linux-kernel

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>
---
 drivers/tty/serial/Kconfig       |  1 +
 drivers/tty/serial/stm32-usart.c | 51 ++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

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 8aefb286bd88..f75691e72729 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -1761,6 +1761,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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function
  2022-04-19  8:53   ` Valentin Caron
@ 2022-04-19  8:59     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 12+ messages in thread
From: Geert Uytterhoeven @ 2022-04-19  8:59 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Greg Kroah-Hartman, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, open list:SERIAL DRIVERS, linux-stm32,
	Linux ARM, Linux Kernel Mailing List

Hi Valentin,

On Tue, Apr 19, 2022 at 10:54 AM Valentin Caron
<valentin.caron@foss.st.com> wrote:
> 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>

Thanks for your patch!

> --- a/drivers/tty/serial/stm32-usart.c
> +++ b/drivers/tty/serial/stm32-usart.c
> @@ -1640,10 +1640,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);

Does it make sense to print this message, i.e. will the user ever see it?
Or is the failure above temporary?
I assume that you have seen this trigger?

> +               return;
> +       }
>         writel_relaxed(ch, port->membase + ofs->tdr);
>  }

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] 12+ messages in thread

* Re: [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function
@ 2022-04-19  8:59     ` Geert Uytterhoeven
  0 siblings, 0 replies; 12+ messages in thread
From: Geert Uytterhoeven @ 2022-04-19  8:59 UTC (permalink / raw)
  To: Valentin Caron
  Cc: Greg Kroah-Hartman, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, open list:SERIAL DRIVERS, linux-stm32,
	Linux ARM, Linux Kernel Mailing List

Hi Valentin,

On Tue, Apr 19, 2022 at 10:54 AM Valentin Caron
<valentin.caron@foss.st.com> wrote:
> 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>

Thanks for your patch!

> --- a/drivers/tty/serial/stm32-usart.c
> +++ b/drivers/tty/serial/stm32-usart.c
> @@ -1640,10 +1640,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);

Does it make sense to print this message, i.e. will the user ever see it?
Or is the failure above temporary?
I assume that you have seen this trigger?

> +               return;
> +       }
>         writel_relaxed(ch, port->membase + ofs->tdr);
>  }

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function
  2022-04-19  8:59     ` Geert Uytterhoeven
@ 2022-04-19 10:33       ` Valentin CARON
  -1 siblings, 0 replies; 12+ messages in thread
From: Valentin CARON @ 2022-04-19 10:33 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, open list:SERIAL DRIVERS, linux-stm32,
	Linux ARM, Linux Kernel Mailing List

On 4/19/22 10:59, Geert Uytterhoeven wrote:
> Hi Valentin,
>
> On Tue, Apr 19, 2022 at 10:54 AM Valentin Caron
> <valentin.caron@foss.st.com> wrote:
>> 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>
> Thanks for your patch!
>
>> --- a/drivers/tty/serial/stm32-usart.c
>> +++ b/drivers/tty/serial/stm32-usart.c
>> @@ -1640,10 +1640,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);
> Does it make sense to print this message, i.e. will the user ever see it?
> Or is the failure above temporary?
> I assume that you have seen this trigger?
>
>> +               return;
>> +       }
>>          writel_relaxed(ch, port->membase + ofs->tdr);
>>   }
> 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,

The failure is temporary. It can appears when the uart is too slow to 
send data.

I never tested the case, but I prefer to show a message to know if the 
console loses a character.

Thanks,
Valentin



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function
@ 2022-04-19 10:33       ` Valentin CARON
  0 siblings, 0 replies; 12+ messages in thread
From: Valentin CARON @ 2022-04-19 10:33 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Greg Kroah-Hartman, Jiri Slaby, Maxime Coquelin,
	Alexandre Torgue, open list:SERIAL DRIVERS, linux-stm32,
	Linux ARM, Linux Kernel Mailing List

On 4/19/22 10:59, Geert Uytterhoeven wrote:
> Hi Valentin,
>
> On Tue, Apr 19, 2022 at 10:54 AM Valentin Caron
> <valentin.caron@foss.st.com> wrote:
>> 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>
> Thanks for your patch!
>
>> --- a/drivers/tty/serial/stm32-usart.c
>> +++ b/drivers/tty/serial/stm32-usart.c
>> @@ -1640,10 +1640,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);
> Does it make sense to print this message, i.e. will the user ever see it?
> Or is the failure above temporary?
> I assume that you have seen this trigger?
>
>> +               return;
>> +       }
>>          writel_relaxed(ch, port->membase + ofs->tdr);
>>   }
> 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,

The failure is temporary. It can appears when the uart is too slow to 
send data.

I never tested the case, but I prefer to show a message to know if the 
console loses a character.

Thanks,
Valentin



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-04-19 10:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19  8:53 [PATCH V3 0/3] serial: stm32: add earlycon and polling mode Valentin Caron
2022-04-19  8:53 ` Valentin Caron
2022-04-19  8:53 ` [PATCH V3 1/3] serial: stm32: remove infinite loop possibility in putchar function Valentin Caron
2022-04-19  8:53   ` Valentin Caron
2022-04-19  8:59   ` Geert Uytterhoeven
2022-04-19  8:59     ` Geert Uytterhoeven
2022-04-19 10:33     ` Valentin CARON
2022-04-19 10:33       ` Valentin CARON
2022-04-19  8:53 ` [PATCH V3 2/3] serial: stm32: add KGDB support Valentin Caron
2022-04-19  8:53   ` Valentin Caron
2022-04-19  8:53 ` [PATCH V3 3/3] serial: stm32: add earlycon support Valentin Caron
2022-04-19  8:53   ` Valentin Caron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.