Devicetree
 help / color / mirror / Atom feed
* [PATCH 0/2] Stabilize serial line numbers on MediaTek Genio boards
@ 2026-07-08 11:17 Carlo Caione
  2026-07-08 11:17 ` [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on " Carlo Caione
  2026-07-08 11:17 ` [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases Carlo Caione
  0 siblings, 2 replies; 7+ messages in thread
From: Carlo Caione @ 2026-07-08 11:17 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
	AngeloGioacchino Del Regno, Greg Kroah-Hartman, Jiri Slaby
  Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	linux-serial, dlechner, jstephan, Carlo Caione

On the MediaTek Genio boards only serial0 is aliased in DT, so every
other enabled UART gets a first-free ttyS line number from the 8250
core at probe time. Line numbers are handed out in probe order, and
probe order is not deterministic once a UART defers on its clocks, so
the console UART can lose ttyS0 to another port.

This was observed on the Genio 700 EVK running the Ubuntu 26.04 generic
kernel: uart0 (the debug console) deferred waiting for its clocks while
uart1 probed first and claimed ttyS0. With console=ttyS0 on the kernel
command line the console then pointed at the wrong UART, and the boot
looked like it had hung on the serial console. The failure is
intermittent and depends purely on probe timing.

Pin the line numbers explicitly instead:

 - Patch 1 aliases every enabled UART on the affected Genio boards
   (mt8365-evk, the mt8390 and mt8395 Genio commons, and the Grinn
   Genio SBC), so DT expresses the intended serial<N> -> ttyS<N>
   mapping.

 - Patch 2 makes the 8250_mtk driver read that alias with
   of_alias_get_id() and seed uart.port.line before registering the
   port, so the 8250 core reserves the requested ttyS slot instead of
   falling back to first-free.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
Carlo Caione (2):
      arm64: dts: mediatek: alias all enabled serial ports on Genio boards
      serial: 8250_mtk: honor DT serial aliases

 arch/arm64/boot/dts/mediatek/mt8365-evk.dts              | 2 ++
 arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi    | 2 ++
 arch/arm64/boot/dts/mediatek/mt8390-grinn-genio-sbc.dtsi | 2 ++
 arch/arm64/boot/dts/mediatek/mt8395-genio-common.dtsi    | 1 +
 drivers/tty/serial/8250/8250_mtk.c                       | 7 ++++++-
 5 files changed, 13 insertions(+), 1 deletion(-)
---
base-commit: 0e35b9b6ec0ffcc5e23cbdec09f5c622ad532b53
change-id: 20260708-ccaione-genio-serial-aliases-e5f2c28b5ff6

Best regards,
--  
Carlo Caione <ccaione@baylibre.com>


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

* [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on Genio boards
  2026-07-08 11:17 [PATCH 0/2] Stabilize serial line numbers on MediaTek Genio boards Carlo Caione
@ 2026-07-08 11:17 ` Carlo Caione
  2026-07-08 11:27   ` sashiko-bot
  2026-07-08 11:17 ` [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases Carlo Caione
  1 sibling, 1 reply; 7+ messages in thread
From: Carlo Caione @ 2026-07-08 11:17 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
	AngeloGioacchino Del Regno, Greg Kroah-Hartman, Jiri Slaby
  Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	linux-serial, dlechner, jstephan, Carlo Caione

Only serial0 is aliased, so the remaining enabled uarts get first-free
line numbers. When the console uart defers on its clocks, another uart
can win line 0: console=ttyS0 then ends up on the wrong connector and
the boot looks like a hang on the serial console, depending on probe
order. Alias every enabled uart so line numbers are stable.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 arch/arm64/boot/dts/mediatek/mt8365-evk.dts              | 2 ++
 arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi    | 2 ++
 arch/arm64/boot/dts/mediatek/mt8390-grinn-genio-sbc.dtsi | 2 ++
 arch/arm64/boot/dts/mediatek/mt8395-genio-common.dtsi    | 1 +
 4 files changed, 7 insertions(+)

diff --git a/arch/arm64/boot/dts/mediatek/mt8365-evk.dts b/arch/arm64/boot/dts/mediatek/mt8365-evk.dts
index a30ee523b0b5..c535de34dfac 100644
--- a/arch/arm64/boot/dts/mediatek/mt8365-evk.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8365-evk.dts
@@ -24,6 +24,8 @@ aliases {
 		mmc0 = &mmc0;
 		mmc1 = &mmc1;
 		serial0 = &uart0;
+		serial1 = &uart1;
+		serial2 = &uart2;
 	};
 
 	chosen {
diff --git a/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi b/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi
index b0c97930a0e6..26e24431d467 100644
--- a/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi
@@ -33,6 +33,8 @@ aliases {
 		mmc0 = &mmc0;
 		mmc1 = &mmc1;
 		serial0 = &uart0;
+		serial1 = &uart1;
+		serial2 = &uart2;
 	};
 
 	backlight_lcm1: backlight-lcm1 {
diff --git a/arch/arm64/boot/dts/mediatek/mt8390-grinn-genio-sbc.dtsi b/arch/arm64/boot/dts/mediatek/mt8390-grinn-genio-sbc.dtsi
index 888248a75e93..51f12328a1d6 100644
--- a/arch/arm64/boot/dts/mediatek/mt8390-grinn-genio-sbc.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8390-grinn-genio-sbc.dtsi
@@ -17,6 +17,8 @@ aliases {
 		i2c5 = &i2c5;
 		i2c6 = &i2c6;
 		serial0 = &uart0;
+		serial1 = &uart1;
+		serial2 = &uart2;
 	};
 
 	chosen {
diff --git a/arch/arm64/boot/dts/mediatek/mt8395-genio-common.dtsi b/arch/arm64/boot/dts/mediatek/mt8395-genio-common.dtsi
index edc5539bebde..86e487fb1832 100644
--- a/arch/arm64/boot/dts/mediatek/mt8395-genio-common.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8395-genio-common.dtsi
@@ -22,6 +22,7 @@ aliases {
 		mmc0 = &mmc0;
 		mmc1 = &mmc1;
 		serial0 = &uart0;
+		serial1 = &uart1;
 	};
 
 	chosen {

-- 
2.55.0


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

* [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases
  2026-07-08 11:17 [PATCH 0/2] Stabilize serial line numbers on MediaTek Genio boards Carlo Caione
  2026-07-08 11:17 ` [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on " Carlo Caione
@ 2026-07-08 11:17 ` Carlo Caione
  2026-07-08 11:26   ` sashiko-bot
  1 sibling, 1 reply; 7+ messages in thread
From: Carlo Caione @ 2026-07-08 11:17 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski, Conor Dooley, Matthias Brugger,
	AngeloGioacchino Del Regno, Greg Kroah-Hartman, Jiri Slaby
  Cc: devicetree, linux-kernel, linux-arm-kernel, linux-mediatek,
	linux-serial, dlechner, jstephan, Carlo Caione

The Genio board DTs provide serial aliases for all enabled UARTs, but
the MTK 8250 driver still registered every port with the default line
number. If uart0 deferred and another UART probed first, the 8250 core
could still assign ttyS0 to the wrong port despite the DT aliases.

Read the serial alias during OF probe and seed uart.port.line before
registering the port so the 8250 core reserves the requested ttyS slot.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/tty/serial/8250/8250_mtk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
index e6a56cf54ae0..841d64f6a707 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -8,6 +8,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/of_irq.h>
 #include <linux/of_platform.h>
 #include <linux/pinctrl/consumer.h>
@@ -521,7 +522,7 @@ static int mtk8250_probe(struct platform_device *pdev)
 	struct uart_8250_port uart = {};
 	struct mtk8250_data *data;
 	struct resource *regs;
-	int irq, err;
+	int irq, err, line;
 	struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
 
 	irq = platform_get_irq(pdev, 0);
@@ -575,6 +576,10 @@ static int mtk8250_probe(struct platform_device *pdev)
 #endif
 
 	if (is_of_node(fwnode)) {
+		line = of_alias_get_id(pdev->dev.of_node, "serial");
+		if (line >= 0)
+			uart.port.line = line;
+
 		/* Disable Rate Fix function */
 		writel(0x0, uart.port.membase +
 			(MTK_UART_RATE_FIX << uart.port.regshift));

-- 
2.55.0


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

* Re: [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases
  2026-07-08 11:17 ` [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases Carlo Caione
@ 2026-07-08 11:26   ` sashiko-bot
  2026-07-08 12:54     ` Carlo Caione
  0 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-07-08 11:26 UTC (permalink / raw)
  To: Carlo Caione; +Cc: devicetree, conor+dt, robh

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Runtime PM APIs are invoked from the UART PM callback before runtime PM is enabled, causing circular dependencies during probe.
--

--- Patch [2]: [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases ---
commit 74b06e9bc5c00de637cbaa988a6208e3815ff355
Author: Carlo Caione <ccaione@baylibre.com>

serial: 8250_mtk: honor DT serial aliases

The Genio board DTs provide serial aliases for all enabled UARTs, but
the MTK 8250 driver still registered every port with the default line
number. If uart0 deferred and another UART probed first, the 8250 core
could still assign ttyS0 to the wrong port despite the DT aliases.

Read the serial alias during OF probe and seed uart.port.line before
registering the port so the 8250 core reserves the requested ttyS slot.

> diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
> index e6a56cf54ae0c..841d64f6a7071 100644
> --- a/drivers/tty/serial/8250/8250_mtk.c
> +++ b/drivers/tty/serial/8250/8250_mtk.c
[ ... ]
> @@ -575,6 +576,10 @@ static int mtk8250_probe(struct platform_device *pdev)
>  #endif
>  
>  	if (is_of_node(fwnode)) {
> +		line = of_alias_get_id(pdev->dev.of_node, "serial");
> +		if (line >= 0)
> +			uart.port.line = line;
> +
>  		/* Disable Rate Fix function */
>  		writel(0x0, uart.port.membase +
>  			(MTK_UART_RATE_FIX << uart.port.regshift));

[Severity: High]
This isn't a bug introduced by this patch, but registering the 8250 port
before enabling runtime PM causes circular dependencies during device probe.

During port registration, the serial core can synchronously invoke the port's
.pm callback (mtk8250_do_pm()). The mtk8250_do_pm() callback executes
pm_runtime_get_sync() and pm_runtime_put_sync_suspend() on an uninitialized
device:

drivers/tty/serial/8250/8250_mtk.c:mtk8250_do_pm() {
    ...
    if (!state)
        pm_runtime_get_sync(port->dev);
    ...
}

This happens further down in mtk8250_probe():

drivers/tty/serial/8250/8250_mtk.c:mtk8250_probe() {
    ...
    data->line = serial8250_register_8250_port(&uart);
    if (data->line < 0)
        return data->line;

    data->rx_wakeup_irq = platform_get_irq_optional(pdev, 1);

    pm_runtime_set_active(&pdev->dev);
    pm_runtime_enable(&pdev->dev);
    ...
}

Could pm_runtime_enable() be called before serial8250_register_8250_port()
to prevent hung worker threads and indefinitely blocked probe tasks?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-ccaione-genio-serial-aliases-v1-0-bf22229e9383@baylibre.com?part=2

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

* Re: [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on Genio boards
  2026-07-08 11:17 ` [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on " Carlo Caione
@ 2026-07-08 11:27   ` sashiko-bot
  2026-07-08 12:58     ` Carlo Caione
  0 siblings, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-07-08 11:27 UTC (permalink / raw)
  To: Carlo Caione; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Incomplete fix: mt8390-tungsten-smarc.dtsi leaves multiple enabled UARTs without aliases, remaining vulnerable to the console probe-deferral race condition.
--

--- Patch [1]: [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on Genio boards ---
commit e24717bbabf68ad0b7411bc7cc53b4c950007efe
Author: Carlo Caione <ccaione@baylibre.com>

arm64: dts: mediatek: alias all enabled serial ports on Genio boards

Only serial0 is aliased, so the remaining enabled uarts get first-free
line numbers. When the console uart defers on its clocks, another uart
can win line 0: console=ttyS0 then ends up on the wrong connector and
the boot looks like a hang on the serial console, depending on probe
order. Alias every enabled uart so line numbers are stable.

[ ... ]

> diff --git a/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi b/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi
> index b0c97930a0e6c..26e24431d467d 100644
> --- a/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8390-genio-common.dtsi
> @@ -33,6 +33,8 @@ aliases {
>  		mmc0 = &mmc0;
>  		mmc1 = &mmc1;
>  		serial0 = &uart0;
> +		serial1 = &uart1;
> +		serial2 = &uart2;
>  	};

[Severity: High]
This isn't a bug introduced by this patch, but does this incomplete fix
leave other MT8390 boards vulnerable to the console probe-deferral race?

Looking at the aliases node in
arch/arm64/boot/dts/mediatek/mt8390-tungsten-smarc.dtsi:

	aliases {
		dsi0 = &disp_dsi0;
		ethernet0 = &eth;
[ ... ]
		rtc1 = &mt6359rtc;
		serial0 = &uart0;
	};

It fails to define serial1 = &uart1; and serial2 = &uart2; for the enabled
secondary UARTs. If the primary console UART (uart0) defers during probe
due to clock dependencies, can a secondary enabled UART (uart1 or uart2)
successfully probe before uart0 is ready and take the first available
unaliased line (ttyS0)?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-ccaione-genio-serial-aliases-v1-0-bf22229e9383@baylibre.com?part=1

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

* Re: [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases
  2026-07-08 11:26   ` sashiko-bot
@ 2026-07-08 12:54     ` Carlo Caione
  0 siblings, 0 replies; 7+ messages in thread
From: Carlo Caione @ 2026-07-08 12:54 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: devicetree, conor+dt, robh

On Wed, Jul 8, 2026 at 1:26 PM <sashiko-bot@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Runtime PM APIs are invoked from the UART PM callback before runtime PM is enabled, causing circular dependencies during probe.
> --

This is out-of-scope. Not going to address this issue in this patchset.

--
Carlo Caione

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

* Re: [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on Genio boards
  2026-07-08 11:27   ` sashiko-bot
@ 2026-07-08 12:58     ` Carlo Caione
  0 siblings, 0 replies; 7+ messages in thread
From: Carlo Caione @ 2026-07-08 12:58 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: devicetree, robh, conor+dt

On Wed, Jul 8, 2026 at 1:27 PM <sashiko-bot@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Incomplete fix: mt8390-tungsten-smarc.dtsi leaves multiple enabled UARTs without aliases, remaining vulnerable to the console probe-deferral race condition.
> --

Alright, let me double check if I missed any board. I'll eventually submit a V2.

--
Carlo Caione

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

end of thread, other threads:[~2026-07-08 12:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 11:17 [PATCH 0/2] Stabilize serial line numbers on MediaTek Genio boards Carlo Caione
2026-07-08 11:17 ` [PATCH 1/2] arm64: dts: mediatek: alias all enabled serial ports on " Carlo Caione
2026-07-08 11:27   ` sashiko-bot
2026-07-08 12:58     ` Carlo Caione
2026-07-08 11:17 ` [PATCH 2/2] serial: 8250_mtk: honor DT serial aliases Carlo Caione
2026-07-08 11:26   ` sashiko-bot
2026-07-08 12:54     ` Carlo Caione

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox