Skip to contentSkip to conversation

Add Amlogic T7 (A311D2) and Khadas VIM4 support

PATCH Superseded Lucas Tanure 3 participants 13 messages Aug 6 – Aug 17

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add Amlogic T7 (A311D2) and Khadas VIM4 support

This series adds initial mainline support for the Amlogic T7 SoC family and the Khadas VIM4 board (A311D2):
- S4-generation UART support
- the T7 platform code
- VIM4 board and defconfig
- VIM4 documentation

Tested on a Khadas VIM4 board, both chainloaded from the vendor U-Boot (tftpboot) and cold-booted from an SD card.

Lucas Tanure (4):
serial: meson: add Amlogic S4 UART support
arm: meson: add Amlogic T7 SoC family support
board: amlogic: add Khadas VIM4 support
doc: board: amlogic: add Khadas VIM4 documentation

 .../amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi |  22 ++++
 arch/arm/include/asm/arch-meson/boot0.h       |  18 +++
 arch/arm/mach-meson/Kconfig                   |  10 ++
 arch/arm/mach-meson/Makefile                  |   1 +
 arch/arm/mach-meson/board-t7.c                |  97 ++++++++++++++
 board/amlogic/vim4/MAINTAINERS                |   8 ++
 board/amlogic/vim4/Makefile                   |   4 +
 board/amlogic/vim4/vim4.c                     |  14 ++
 configs/khadas-vim4_defconfig                 |  27 ++++
 doc/board/amlogic/index.rst                   | 119 ++++++++---------
 doc/board/amlogic/khadas-vim4.rst             | 122 ++++++++++++++++++
 drivers/serial/serial_meson.c                 |  51 ++++++--
 12 files changed, 421 insertions(+), 72 deletions(-)
 create mode 100644 arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi
 create mode 100644 arch/arm/include/asm/arch-meson/boot0.h
 create mode 100644 arch/arm/mach-meson/board-t7.c
 create mode 100644 board/amlogic/vim4/MAINTAINERS
 create mode 100644 board/amlogic/vim4/Makefile
 create mode 100644 board/amlogic/vim4/vim4.c
 create mode 100644 configs/khadas-vim4_defconfig
 create mode 100644 doc/board/amlogic/khadas-vim4.rst
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/4 serial: meson: add Amlogic S4 UART support

The S4-generation UART (S4, T7, ...) derives its baud rate from the 24 MHz crystal divided by 2, selected via the XTAL_DIV2 bit in the baud rate register, while older SoCs divide the crystal by 3. Add the "amlogic,meson-s4-uart" compatible with driver data selecting the div-by-2 scheme, matching the Linux driver (meson_s4_uart_data) and the configuration the vendor BL2 programs on T7 hardware.

Older SoCs keep the existing div-by-3 behaviour: Linux also uses div-by-2 on G12A, but both modes work there and switching would risk regressing boards that have shipped with div-by-3 for years.

Also drain the transmitter before changing the baud rate so in-flight characters are not garbled, as the Linux driver does.

Assisted-by Claude:claude-fable-5
---
 drivers/serial/serial_meson.c | 51 ++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 13 deletions(-)
drivers/serial/serial_meson.c +38 -13
index cc71381f87e..d909fedcfc4 100644
@@ -62,26 +62,49 @@ struct meson_serial_plat {
 #define AML_UART_REG5_USE_NEW_BAUD	BIT(23) /* default 1 (use new baud rate register) */
 #define AML_UART_REG5_BAUD_MASK		0x7fffff
 
+/* Driver data flags */
+#define MESON_UART_XTAL_DIV2	BIT(0)
+
 #if CONFIG_IS_ENABLED(DM_SERIAL)
-static u32 meson_calc_baud_divisor(ulong src_rate, u32 baud)
+static u32 meson_uart_xtal_div(struct udevice *dev)
+{
+	/*
+	 * S4-generation UARTs (S4, T7, ...) derive the baud rate from the
+	 * crystal divided by 2, older ones divide by 3.
+	 */
+	return (dev_get_driver_data(dev) & MESON_UART_XTAL_DIV2) ? 2 : 3;
+}
+
+static u32 meson_calc_baud_divisor(struct udevice *dev, ulong src_rate, u32 baud)
 {
 	/*
 	 * Usually src_rate is 24 MHz (from crystal) as clock source for serial
-	 * device. Since 8 Mb/s is the maximum supported baud rate, use div by 3
-	 * to derive baud rate. This choice is used also in meson_serial_setbrg.
+	 * device. Since 8 Mb/s is the maximum supported baud rate, use a
+	 * divided crystal to derive the baud rate. This choice is used also in
+	 * meson_serial_setbrg.
 	 */
-	return DIV_ROUND_CLOSEST(src_rate / 3, baud) - 1;
+	return DIV_ROUND_CLOSEST(src_rate / meson_uart_xtal_div(dev), baud) - 1;
 }
 
-static void meson_serial_set_baud(struct meson_uart *uart, ulong src_rate, u32 baud)
+static void meson_serial_set_baud(struct udevice *dev, struct meson_uart *uart,
+				  ulong src_rate, u32 baud)
 {
 	/*
-	 * Set crystal divided by 3 (regardless of device tree clock property)
+	 * Set the divided crystal (regardless of device tree clock property)
 	 * as clock source and the corresponding divisor to approximate baud
 	 */
-	u32 divisor = meson_calc_baud_divisor(src_rate, baud);
+	u32 divisor = meson_calc_baud_divisor(dev, src_rate, baud);
 	u32 val = AML_UART_REG5_USE_XTAL_CLK | AML_UART_REG5_USE_NEW_BAUD |
 		(divisor & AML_UART_REG5_BAUD_MASK);
+
+	if (meson_uart_xtal_div(dev) == 2)
+		val |= AML_UART_REG5_XTAL_DIV2;
+
+	/* Drain the transmitter before changing the baud rate */
+	while ((readl(&uart->status) & (AML_UART_TX_EMPTY | AML_UART_XMIT_BUSY))
+	       != AML_UART_TX_EMPTY)
+		;
+
 	writel(val, &uart->reg5);
 }
 
@@ -109,7 +132,7 @@ static int meson_serial_probe(struct udevice *dev)
 		return ret;
 	ulong rate = clk_get_rate(&per_clk);
 
-	meson_serial_set_baud(uart, rate, CONFIG_BAUDRATE);
+	meson_serial_set_baud(dev, uart, rate, CONFIG_BAUDRATE);
 	meson_serial_init(uart);
 
 	return 0;
@@ -165,8 +188,9 @@ static int meson_serial_setbrg(struct udevice *dev, const int baud)
 {
 	/*
 	 * Change device baud rate if baud is reasonable (considering a 23 bit
-	 * counter with an 8 MHz clock input) and the actual baud
-	 * rate is within 2% of the requested value (2% is arbitrary).
+	 * counter with an 8 MHz, or 12 MHz for XTAL_DIV2 devices, clock input)
+	 * and the actual baud rate is within 2% of the requested value (2% is
+	 * arbitrary).
 	 */
 	if (baud < 1 || baud > 8000000)
 		return -EINVAL;
@@ -179,14 +203,14 @@ static int meson_serial_setbrg(struct udevice *dev, const int baud)
 	if (ret)
 		return ret;
 	ulong rate = clk_get_rate(&per_clk);
-	u32 divisor = meson_calc_baud_divisor(rate, baud);
-	u32 calc_baud = (rate / 3) / (divisor + 1);
+	u32 divisor = meson_calc_baud_divisor(dev, rate, baud);
+	u32 calc_baud = (rate / meson_uart_xtal_div(dev)) / (divisor + 1);
 	u32 calc_err = baud > calc_baud ? baud - calc_baud : calc_baud - baud;
 
 	if (((calc_err * 100) / baud) > 2)
 		return -EINVAL;
 
-	meson_serial_set_baud(uart, rate, baud);
+	meson_serial_set_baud(dev, uart, rate, baud);
 
 	return 0;
 }
@@ -244,6 +268,7 @@ static const struct udevice_id meson_serial_ids[] = {
 	{ .compatible = "amlogic,meson-uart" },
 	{ .compatible = "amlogic,meson-gx-uart" },
 	{ .compatible = "amlogic,meson-a1-uart" },
+	{ .compatible = "amlogic,meson-s4-uart", .data = MESON_UART_XTAL_DIV2 },
 	{ }
 };
 
Signature · 1 line
2.55.0
#6 lore raw

PATCH 2/4 arm: meson: add Amlogic T7 SoC family support

In reply to Lucas Tanure

Add initial support for the Amlogic T7 family (A311D2). U-Boot runs as BL33, loaded at address 0x0 and entered from the vendor BL31 at EL2, either uncompressed or LZ4-compressed inside the boot image (the BL31 decompresses it).

The secure firmware writes the SCS device keys into the first page of the loaded BL33 image (2 KiB for the BL33 key followed by 2 KiB for the kernel key). Reserve that page with a boot0 hook, as the vendor U-Boot does, so the keys do not overwrite U-Boot's entry code.

The firmware also enters BL33 with the non-secure watchdog running:
disable it in board_init(), otherwise the board is reset about a minute after boot.

The memory map leaves 0x05100000 - 0x09000000 unmapped: the secure world owns this span (the BL31 and BL32 runtime zones described in the upstream devicetree, plus further firmware-protected pages), and this matches the vendor bootloader's own map. The whole span is also added to the devicetree and EFI reserved memory at boot time so no allocation is placed in memory U-Boot cannot access.

get_effective_memsize() is capped at 0xdf800000 because the top 8 MiB of the first DRAM bank contain pages the secure world protects at runtime; U-Boot and its heap must stay below them.

Assisted-by Claude:claude-fable-5
---
 arch/arm/include/asm/arch-meson/boot0.h | 18 +++++
 arch/arm/mach-meson/Kconfig             | 10 +++
 arch/arm/mach-meson/Makefile            |  1 +
 arch/arm/mach-meson/board-t7.c          | 97 +++++++++++++++++++++++++
 4 files changed, 126 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-meson/boot0.h
 create mode 100644 arch/arm/mach-meson/board-t7.c
arch/arm/include/asm/arch-meson/boot0.h new file +18 -0
new file mode 100644
index 00000000000..3ec085ccd64
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2026 Lucas Tanure <[email protected]>
+ */
+
+#ifndef __MESON_BOOT0_H
+#define __MESON_BOOT0_H
+
+/*
+ * The T7-family secure firmware writes the SCS device keys into the
+ * first page of the loaded BL33 image (2048 bytes for the BL33 key
+ * followed by 2048 bytes for the kernel key). Keep that page reserved
+ * so the keys do not overwrite U-Boot's entry code.
+ */
+	b	reset
+	.space	4096
+
+#endif /* __MESON_BOOT0_H */
arch/arm/mach-meson/Kconfig +10 -0
index c687ef822a2..40aafc0b922 100644
@@ -67,6 +67,15 @@ config MESON_A1
 	help
 	  Select this if your SoC is an A113L
 
+config MESON_T7
+	bool "T7"
+	select MESON64_COMMON
+	select ENABLE_ARM_SOC_BOOT0_HOOK
+	imply OF_UPSTREAM
+	help
+	  Select this if your SoC is from the Amlogic T7 family, like
+	  the A311D2 found on the Khadas VIM4 board.
+
 endchoice
 
 config SYS_SOC
@@ -91,6 +100,7 @@ config SYS_BOARD
 	default "q200" if MESON_GXM
 	default "s400" if MESON_AXG
 	default "u200" if MESON_G12A
+	default "vim4" if MESON_T7
 	default ""
 	help
 	  This option contains information about board name.
arch/arm/mach-meson/Makefile +1 -0
index 08a24d4b24f..dc2bc0ceecb 100644
@@ -17,3 +17,4 @@ endif
 obj-$(CONFIG_MESON_AXG) += board-axg.o
 obj-$(CONFIG_MESON_G12A) += board-g12a.o
 obj-$(CONFIG_MESON_A1) += board-a1.o
+obj-$(CONFIG_MESON_T7) += board-t7.o
arch/arm/mach-meson/board-t7.c new file +97 -0

97 lines not on this page · raw message

Signature · 1 line
2.55.0
#8 lore raw

PATCH 3/4 board: amlogic: add Khadas VIM4 support

In reply to Lucas Tanure

Add initial support for the Khadas VIM4 board (Amlogic A311D2, T7 family): UART console, DRAM (first bank), PSCI reset through BL31 and the secure monitor. Storage, network and USB support come later.

The image is position independent with TEXT_BASE=0, so the same u-boot.bin can be chainloaded from the vendor U-Boot for development or packaged as BL33 into the vendor boot image.

The console runs at 921600 baud, the serial console convention on the VIM4 (this is also how BL2 configures uart_a).

Assisted-by Claude:claude-fable-5
---
 .../amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi | 22 +++++++++++++++
 board/amlogic/vim4/MAINTAINERS                |  7 +++++
 board/amlogic/vim4/Makefile                   |  4 +++
 board/amlogic/vim4/vim4.c                     | 14 ++++++++++
 configs/khadas-vim4_defconfig                 | 27 +++++++++++++++++++
 5 files changed, 74 insertions(+)
 create mode 100644 arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi
 create mode 100644 board/amlogic/vim4/MAINTAINERS
 create mode 100644 board/amlogic/vim4/Makefile
 create mode 100644 board/amlogic/vim4/vim4.c
 create mode 100644 configs/khadas-vim4_defconfig
arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi new file +22 -0
new file mode 100644
index 00000000000..dde2cd804e3
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2026 Lucas Tanure <[email protected]>
+ */
+
+/ {
+	chosen {
+		stdout-path = "serial0:921600n8";
+	};
+
+	soc {
+		bootph-all;
+	};
+};
+
+&uart_a {
+	bootph-all;
+};
+
+&xtal {
+	bootph-all;
+};
board/amlogic/vim4/MAINTAINERS new file +7 -0
new file mode 100644
index 00000000000..5e1ec98b571
@@ -0,0 +1,7 @@
+VIM4
+M:	Lucas Tanure <[email protected]>
+S:	Maintained
+L:	[email protected]
+F:	board/amlogic/vim4/
+F:	configs/khadas-vim4_defconfig
+F:	arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi
board/amlogic/vim4/Makefile new file +4 -0
new file mode 100644
index 00000000000..0cc4078c549
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0+
+# (C) Copyright 2026 Lucas Tanure <[email protected]>
+
+obj-y	:= vim4.o
board/amlogic/vim4/vim4.c new file +14 -0
new file mode 100644
index 00000000000..5db3deefe0e
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2026 Lucas Tanure <[email protected]>
+ */
+
+#include <init.h>
+#include <asm/arch/eth.h>
+
+int misc_init_r(void)
+{
+	meson_generate_serial_ethaddr();
+
+	return 0;
+}
configs/khadas-vim4_defconfig new file +27 -0
new file mode 100644
index 00000000000..10a64c07a88
@@ -0,0 +1,27 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_ARCH_MESON=y
+CONFIG_TEXT_BASE=0x00000000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_ENV_SIZE=0x2000
+CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="amlogic/amlogic-t7-a311d2-khadas-vim4"
+CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_MESON_T7=y
+CONFIG_SYS_LOAD_ADDR=0x10000000
+CONFIG_DEBUG_UART_BASE=0xfe078000
+CONFIG_DEBUG_UART_CLOCK=24000000
+CONFIG_IDENT_STRING=" khadas-vim4"
+CONFIG_DEBUG_UART=y
+CONFIG_OF_BOARD_SETUP=y
+# CONFIG_DISPLAY_CPUINFO is not set
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_SYS_PROMPT="kvim4> "
+# CONFIG_CMD_BDI is not set
+# CONFIG_CMD_IMI is not set
+CONFIG_CMD_CACHE=y
+CONFIG_OF_CONTROL=y
+CONFIG_BAUDRATE=921600
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_DEBUG_UART_SKIP_INIT=y
+CONFIG_MESON_SERIAL=y
Signature · 1 line
2.55.0
#10 lore raw

PATCH 4/4 doc: board: amlogic: add Khadas VIM4 documentation

In reply to Lucas Tanure

Document building U-Boot for the Khadas VIM4, chainloading it from the vendor U-Boot for development, and packaging the boot image with the vendor tooling, and add the A311D2 to the support matrix.

Notably, the SD card image layout differs from older Amlogic SoCs:
sector 0 is a checksummed BootROM header (a partition table may coexist in its MBR slots), so when writing the bootloader the first sector must be written along with it.

Assisted-by Claude:claude-fable-5
---
 board/amlogic/vim4/MAINTAINERS    |   1 +
 doc/board/amlogic/index.rst       | 119 ++++++++++++++---------------
 doc/board/amlogic/khadas-vim4.rst | 122 ++++++++++++++++++++++++++++++
 3 files changed, 183 insertions(+), 59 deletions(-)
 create mode 100644 doc/board/amlogic/khadas-vim4.rst
board/amlogic/vim4/MAINTAINERS +1 -0
index 5e1ec98b571..b2e5717e846 100644
@@ -5,3 +5,4 @@ L:	[email protected]
 F:	board/amlogic/vim4/
 F:	configs/khadas-vim4_defconfig
 F:	arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi
+F:	doc/board/amlogic/khadas-vim4.rst
doc/board/amlogic/index.rst +60 -59

131 lines not on this page · raw message

doc/board/amlogic/khadas-vim4.rst new file +122 -0

122 lines not on this page · raw message

Signature · 1 line
2.55.0
#11 lore raw
In reply to Lucas Tanure

Hi Lucas,

Quoted 7 lines · Lucas Tanure

This series adds initial mainline support for the Amlogic T7 SoC family and the Khadas VIM4 board (A311D2):
- S4-generation UART support
- the T7 platform code
- VIM4 board and defconfig
- VIM4 documentation

Quoted 8 lines

Tested on a Khadas VIM4 board, both chainloaded from the vendor U-Boot (tftpboot) and cold-booted from an SD card.

Lucas Tanure (4):
serial: meson: add Amlogic S4 UART support
arm: meson: add Amlogic T7 SoC family support
board: amlogic: add Khadas VIM4 support
doc: board: amlogic: add Khadas VIM4 documentation

Overall this looks good, I'll review all the changes closely,

Neil

Quoted 23 lines
  .../amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi |  22 ++++
  arch/arm/include/asm/arch-meson/boot0.h       |  18 +++
  arch/arm/mach-meson/Kconfig                   |  10 ++
  arch/arm/mach-meson/Makefile                  |   1 +
  arch/arm/mach-meson/board-t7.c                |  97 ++++++++++++++
  board/amlogic/vim4/MAINTAINERS                |   8 ++
  board/amlogic/vim4/Makefile                   |   4 +
  board/amlogic/vim4/vim4.c                     |  14 ++
  configs/khadas-vim4_defconfig                 |  27 ++++
  doc/board/amlogic/index.rst                   | 119 ++++++++---------
  doc/board/amlogic/khadas-vim4.rst             | 122 ++++++++++++++++++
  drivers/serial/serial_meson.c                 |  51 ++++++--
  12 files changed, 421 insertions(+), 72 deletions(-)

create mode 100644 arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi create mode 100644 arch/arm/include/asm/arch-meson/boot0.h create mode 100644 arch/arm/mach-meson/board-t7.c
create mode 100644 board/amlogic/vim4/MAINTAINERS
create mode 100644 board/amlogic/vim4/Makefile
create mode 100644 board/amlogic/vim4/vim4.c
create mode 100644 configs/khadas-vim4_defconfig
create mode 100644 doc/board/amlogic/khadas-vim4.rst

#2 lore raw

Re: [PATCH 1/4] serial: meson: add Amlogic S4 UART support

In reply to Lucas Tanure
Quoted 7 lines · Lucas Tanure via groups.io

The S4-generation UART (S4, T7, ...) derives its baud rate from the 24 MHz crystal divided by 2, selected via the XTAL_DIV2 bit in the baud rate register, while older SoCs divide the crystal by 3. Add the "amlogic,meson-s4-uart" compatible with driver data selecting the div-by-2 scheme, matching the Linux driver (meson_s4_uart_data) and the configuration the vendor BL2 programs on T7 hardware.

Quoted 8 lines

Older SoCs keep the existing div-by-3 behaviour: Linux also uses div-by-2 on G12A, but both modes work there and switching would risk regressing boards that have shipped with div-by-3 for years.

Also drain the transmitter before changing the baud rate so in-flight characters are not garbled, as the Linux driver does.

Assisted-by Claude:claude-fable-5

As I understand it, LLM-assisted patches are not welcome in U-Boot right
now: https://lore.kernel.org/u-boot/20260515220758.GM1858239@bill-the-cat/

AFAIK there isn't an official AI policy yet, but it seems the concensus on that matter is currently "please don't". Sorry.

Quoted 115 lines

---
drivers/serial/serial_meson.c | 51 ++++++++++++++++++++++++++---------

1 file changed, 38 insertions(+), 13 deletions(-)
drivers/serial/serial_meson.c +38 -13
index cc71381f87e..d909fedcfc4 100644
@@ -62,26 +62,49 @@ struct meson_serial_plat {
 #define AML_UART_REG5_USE_NEW_BAUD	BIT(23) /* default 1 (use new baud rate register) */
 #define AML_UART_REG5_BAUD_MASK		0x7fffff
 
+/* Driver data flags */
+#define MESON_UART_XTAL_DIV2	BIT(0)
+
 #if CONFIG_IS_ENABLED(DM_SERIAL)
-static u32 meson_calc_baud_divisor(ulong src_rate, u32 baud)
+static u32 meson_uart_xtal_div(struct udevice *dev)
+{
+	/*
+	 * S4-generation UARTs (S4, T7, ...) derive the baud rate from the
+	 * crystal divided by 2, older ones divide by 3.
+	 */
+	return (dev_get_driver_data(dev) & MESON_UART_XTAL_DIV2) ? 2 : 3;
+}
+
+static u32 meson_calc_baud_divisor(struct udevice *dev, ulong src_rate, u32 baud)
 {
 	/*
 	 * Usually src_rate is 24 MHz (from crystal) as clock source for serial
-	 * device. Since 8 Mb/s is the maximum supported baud rate, use div by 3
-	 * to derive baud rate. This choice is used also in meson_serial_setbrg.
+	 * device. Since 8 Mb/s is the maximum supported baud rate, use a
+	 * divided crystal to derive the baud rate. This choice is used also in
+	 * meson_serial_setbrg.
 	 */
-	return DIV_ROUND_CLOSEST(src_rate / 3, baud) - 1;
+	return DIV_ROUND_CLOSEST(src_rate / meson_uart_xtal_div(dev), baud) - 1;
 }
 
-static void meson_serial_set_baud(struct meson_uart *uart, ulong src_rate, u32 baud)
+static void meson_serial_set_baud(struct udevice *dev, struct meson_uart *uart,
+				  ulong src_rate, u32 baud)
 {
 	/*
-	 * Set crystal divided by 3 (regardless of device tree clock property)
+	 * Set the divided crystal (regardless of device tree clock property)
 	 * as clock source and the corresponding divisor to approximate baud
 	 */
-	u32 divisor = meson_calc_baud_divisor(src_rate, baud);
+	u32 divisor = meson_calc_baud_divisor(dev, src_rate, baud);
 	u32 val = AML_UART_REG5_USE_XTAL_CLK | AML_UART_REG5_USE_NEW_BAUD |
 		(divisor & AML_UART_REG5_BAUD_MASK);
+
+	if (meson_uart_xtal_div(dev) == 2)
+		val |= AML_UART_REG5_XTAL_DIV2;
+
+	/* Drain the transmitter before changing the baud rate */
+	while ((readl(&uart->status) & (AML_UART_TX_EMPTY | AML_UART_XMIT_BUSY))
+	       != AML_UART_TX_EMPTY)
+		;
+
 	writel(val, &uart->reg5);
 }
 
@@ -109,7 +132,7 @@ static int meson_serial_probe(struct udevice *dev)
 		return ret;
 	ulong rate = clk_get_rate(&per_clk);
 
-	meson_serial_set_baud(uart, rate, CONFIG_BAUDRATE);
+	meson_serial_set_baud(dev, uart, rate, CONFIG_BAUDRATE);
 	meson_serial_init(uart);
 
 	return 0;
@@ -165,8 +188,9 @@ static int meson_serial_setbrg(struct udevice *dev, const int baud)
 {
 	/*
 	 * Change device baud rate if baud is reasonable (considering a 23 bit
-	 * counter with an 8 MHz clock input) and the actual baud
-	 * rate is within 2% of the requested value (2% is arbitrary).
+	 * counter with an 8 MHz, or 12 MHz for XTAL_DIV2 devices, clock input)
+	 * and the actual baud rate is within 2% of the requested value (2% is
+	 * arbitrary).
 	 */
 	if (baud < 1 || baud > 8000000)
 		return -EINVAL;
@@ -179,14 +203,14 @@ static int meson_serial_setbrg(struct udevice *dev, const int baud)
 	if (ret)
 		return ret;
 	ulong rate = clk_get_rate(&per_clk);
-	u32 divisor = meson_calc_baud_divisor(rate, baud);
-	u32 calc_baud = (rate / 3) / (divisor + 1);
+	u32 divisor = meson_calc_baud_divisor(dev, rate, baud);
+	u32 calc_baud = (rate / meson_uart_xtal_div(dev)) / (divisor + 1);
 	u32 calc_err = baud > calc_baud ? baud - calc_baud : calc_baud - baud;
 
 	if (((calc_err * 100) / baud) > 2)
 		return -EINVAL;
 
-	meson_serial_set_baud(uart, rate, baud);
+	meson_serial_set_baud(dev, uart, rate, baud);
 
 	return 0;
 }
@@ -244,6 +268,7 @@ static const struct udevice_id meson_serial_ids[] = {
 	{ .compatible = "amlogic,meson-uart" },
 	{ .compatible = "amlogic,meson-gx-uart" },
 	{ .compatible = "amlogic,meson-a1-uart" },
+	{ .compatible = "amlogic,meson-s4-uart", .data = MESON_UART_XTAL_DIV2 },
 	{ }
 };
 
Signature · 1 line
2.55.0

Best regards,
Ferass

#12 lore raw
In reply to Lucas Tanure
Quoted 7 lines · Lucas Tanure via groups.io

This series adds initial mainline support for the Amlogic T7 SoC family and the Khadas VIM4 board (A311D2):
- S4-generation UART support
- the T7 platform code
- VIM4 board and defconfig
- VIM4 documentation

Quoted 9 lines

Tested on a Khadas VIM4 board, both chainloaded from the vendor U-Boot (tftpboot) and cold-booted from an SD card.

Lucas Tanure (4):
serial: meson: add Amlogic S4 UART support
arm: meson: add Amlogic T7 SoC family support
board: amlogic: add Khadas VIM4 support
doc: board: amlogic: add Khadas VIM4 documentation

You made a typo on my email address, I'm [email protected], not [email protected] ;) I still received your patchset though (via u-boot-amlogic/u-boot ML), this is just for future patch revisions.

Best regards,
Ferass

#7 lore raw

Re: [PATCH 2/4] arm: meson: add Amlogic T7 SoC family support

In reply to Lucas Tanure
Quoted 21 lines · Lucas Tanure via groups.io

Add initial support for the Amlogic T7 family (A311D2). U-Boot runs as BL33, loaded at address 0x0 and entered from the vendor BL31 at EL2, either uncompressed or LZ4-compressed inside the boot image (the BL31 decompresses it).

The secure firmware writes the SCS device keys into the first page of the loaded BL33 image (2 KiB for the BL33 key followed by 2 KiB for the kernel key). Reserve that page with a boot0 hook, as the vendor U-Boot does, so the keys do not overwrite U-Boot's entry code.

The firmware also enters BL33 with the non-secure watchdog running:
disable it in board_init(), otherwise the board is reset about a minute after boot.

The memory map leaves 0x05100000 - 0x09000000 unmapped: the secure world owns this span (the BL31 and BL32 runtime zones described in the upstream devicetree, plus further firmware-protected pages), and this matches the vendor bootloader's own map. The whole span is also added to the devicetree and EFI reserved memory at boot time so no allocation is placed in memory U-Boot cannot access.

Quoted 5 lines

get_effective_memsize() is capped at 0xdf800000 because the top 8 MiB of the first DRAM bank contain pages the secure world protects at runtime; U-Boot and its heap must stay below them.

Assisted-by Claude:claude-fable-5

Same as on the first patch.

Quoted 41 lines

---

arch/arm/include/asm/arch-meson/boot0.h | 18 +++++
arch/arm/mach-meson/Kconfig             | 10 +++
arch/arm/mach-meson/Makefile            |  1 +
arch/arm/mach-meson/board-t7.c          | 97 +++++++++++++++++++++++++
4 files changed, 126 insertions(+)

create mode 100644 arch/arm/include/asm/arch-meson/boot0.h create mode 100644 arch/arm/mach-meson/board-t7.c

arch/arm/include/asm/arch-meson/boot0.h new file +18 -0
new file mode 100644
index 00000000000..3ec085ccd64
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2026 Lucas Tanure <[email protected]>
+ */
+
+#ifndef __MESON_BOOT0_H
+#define __MESON_BOOT0_H
+
+/*
+ * The T7-family secure firmware writes the SCS device keys into the
+ * first page of the loaded BL33 image (2048 bytes for the BL33 key
+ * followed by 2048 bytes for the kernel key). Keep that page reserved
+ * so the keys do not overwrite U-Boot's entry code.
+ */
+	b	reset
+	.space	4096
+
+#endif /* __MESON_BOOT0_H */
arch/arm/mach-meson/Kconfig +0 -0
index c687ef822a2..40aafc0b922 100644
@@ -67,6 +67,15 @@ config MESON_A1
 	help
 	  Select this if your SoC is an A113L

arch/arm/mach-meson/Kconfig config MESON_A1 · line 78

Quoted 10 lines
arch/arm/mach-meson/Kconfig +9 -0
 
+config MESON_T7
+	bool "T7"
+	select MESON64_COMMON
+	select ENABLE_ARM_SOC_BOOT0_HOOK
+	imply OF_UPSTREAM
+	help
+	  Select this if your SoC is from the Amlogic T7 family, like
+	  the A311D2 found on the Khadas VIM4 board.
+

I would shorten this to:

help
Select this if your SoC is an A311D2

to match other SoCs' help message.

Quoted 37 lines

endchoice

config SYS_SOC

arch/arm/mach-meson/Kconfig +1 -0
@@ -91,6 +100,7 @@ config SYS_BOARD
 	default "q200" if MESON_GXM
 	default "s400" if MESON_AXG
 	default "u200" if MESON_G12A
+	default "vim4" if MESON_T7
 	default ""
 	help
 	  This option contains information about board name.
arch/arm/mach-meson/Makefile +0 -0
index 08a24d4b24f..dc2bc0ceecb 100644
@@ -17,3 +17,4 @@ endif

obj-$(CONFIG_MESON_AXG) += board-axg.o
obj-$(CONFIG_MESON_G12A) += board-g12a.o
obj-$(CONFIG_MESON_A1) += board-a1.o

arch/arm/mach-meson/Makefile +1 -0
+obj-$(CONFIG_MESON_T7) += board-t7.o
arch/arm/mach-meson/board-t7.c new file +11 -0
new file mode 100644
index 00000000000..a6ccec25c0e
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2026 Lucas Tanure <[email protected]>
+ */
+
+#include <init.h>
+#include <asm/arch/boot.h>
+#include <asm/arch/mem.h>
+#include <asm/armv8/mmu.h>
+#include <asm/global_data.h>
+#include <asm/io.h>

arch/arm/mach-meson/board-t7.c line 21

Quoted 10 lines
arch/arm/mach-meson/board-t7.c new file +10 -0
+#include <linux/bitops.h>
+#include <linux/compiler.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define T7_WDT_CTRL		0xfe002100
+#define T7_WDT_CTRL_EN		BIT(18)
+

These should probably go in a header file? E.g. asm/arch/t7.h?

arch/arm/mach-meson/board-t7.c line 28

Quoted 7 lines
arch/arm/mach-meson/board-t7.c new file +7 -0
+int board_init(void)
+{
+	/*
+	 * The secure firmware boots BL33 with the watchdog running,
+	 * disable it.
+	 */
+	writel(readl(T7_WDT_CTRL) & ~T7_WDT_CTRL_EN, T7_WDT_CTRL);

In the future it might make sense to write a proper watchdog driver. Though I'm also guilty for doing it this way in U-Boot SPL gxbb/gxl (I think eventually I'll remove this handling there and have U-Boot proper manage the watchdog).

Then you can drop this board_init() function entirely. With that said I won't feel bad if you keep it that way for now.

Quoted 5 lines
arch/arm/mach-meson/board-t7.c new file +5 -0
+
+	return 0;
+}
+
+/*

arch/arm/mach-meson/board-t7.c line 43

Quoted 10 lines
arch/arm/mach-meson/board-t7.c new file +10 -0
+ * The secure world owns 0x05000000 - 0x09000000: it contains the BL31
+ * and BL32 runtime zones (also described as reserved-memory in the
+ * upstream devicetree) and further firmware-protected pages, and is
+ * left unmapped in t7_mem_map below. Reserve the whole span so nothing
+ * (EFI allocations, boot-time relocations) is ever placed in memory
+ * U-Boot cannot access.
+ */
+#define T7_SECMON_RSVMEM_START	0x05000000UL
+#define T7_SECMON_RSVMEM_SIZE	0x04000000UL
+

This too, should probably go in a header file.

arch/arm/mach-meson/board-t7.c line 45

Quoted 2 lines
arch/arm/mach-meson/board-t7.c new file +2 -0
+void meson_init_reserved_memory(__maybe_unused void *fdt)
+{

Why __maybe_unused ?

Quoted 66 lines
arch/arm/mach-meson/board-t7.c new file +52 -0
+	meson_board_add_reserved_memory(fdt, T7_SECMON_RSVMEM_START,
+					T7_SECMON_RSVMEM_SIZE);
+}
+
+int meson_get_boot_device(void)
+{
+	return -ENOSYS;
+}
+
+phys_size_t get_effective_memsize(void)
+{
+	/*
+	 * The top 8 MiB of the first DRAM bank contain pages the secure
+	 * world protects at runtime, keep U-Boot below them.
+	 */
+	return min(gd->ram_size, (phys_size_t)0xdf800000);
+}
+
+static struct mm_region t7_mem_map[] = {
+	{
+		/* DRAM below the secure monitor reserved zone */
+		.virt = 0x00000000UL,
+		.phys = 0x00000000UL,
+		.size = 0x05100000UL,
+		.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+			 PTE_BLOCK_INNER_SHARE
+	}, {
+		/*
+		 * DRAM between the secure monitor reserved zone and the
+		 * end of the first bank. 0x05100000 - 0x09000000 is
+		 * protected by the secure world and must not be mapped.
+		 */
+		.virt = 0x09000000UL,
+		.phys = 0x09000000UL,
+		.size = 0xd7000000UL,
+		.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+			 PTE_BLOCK_INNER_SHARE
+	}, {
+		/* Peripherals, GIC, ... */
+		.virt = 0xe0000000UL,
+		.phys = 0xe0000000UL,
+		.size = 0x20000000UL,
+		.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
+			 PTE_BLOCK_NON_SHARE |
+			 PTE_BLOCK_PXN | PTE_BLOCK_UXN
+	}, {
+		/* List terminator */
+		0,
+	}
+};
+
+struct mm_region *mem_map = t7_mem_map;
Signature · 11 lines
2.55.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#3015): https://groups.io/g/u-boot-amlogic/message/3015
Mute This Topic: https://groups.io/mt/120681747/8399868
Group Owner: [email protected]
Unsubscribe: https://groups.io/g/u-boot-amlogic/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Best regards,
Ferass

#9 lore raw

Re: [PATCH 3/4] board: amlogic: add Khadas VIM4 support

In reply to Lucas Tanure
Quoted 44 lines · Lucas Tanure via groups.io

Add initial support for the Khadas VIM4 board (Amlogic A311D2, T7 family): UART console, DRAM (first bank), PSCI reset through BL31 and the secure monitor. Storage, network and USB support come later.

The image is position independent with TEXT_BASE=0, so the same u-boot.bin can be chainloaded from the vendor U-Boot for development or packaged as BL33 into the vendor boot image.

The console runs at 921600 baud, the serial console convention on the VIM4 (this is also how BL2 configures uart_a).

Assisted-by Claude:claude-fable-5

---

.../amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi | 22 +++++++++++++++
board/amlogic/vim4/MAINTAINERS                |  7 +++++
board/amlogic/vim4/Makefile                   |  4 +++
board/amlogic/vim4/vim4.c                     | 14 ++++++++++
configs/khadas-vim4_defconfig                 | 27 +++++++++++++++++++
5 files changed, 74 insertions(+)

create mode 100644 arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi create mode 100644 board/amlogic/vim4/MAINTAINERS
create mode 100644 board/amlogic/vim4/Makefile
create mode 100644 board/amlogic/vim4/vim4.c
create mode 100644 configs/khadas-vim4_defconfig

arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi new file +12 -0
new file mode 100644
index 00000000000..dde2cd804e3
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (c) 2026 Lucas Tanure <[email protected]>
+ */
+
+/ {
+	chosen {
+		stdout-path = "serial0:921600n8";
+	};
+
+	soc {
+		bootph-all;

arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi line 22

Quoted 10 lines
arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi new file +10 -0
+	};
+};
+
+&uart_a {
+	bootph-all;
+};
+
+&xtal {
+	bootph-all;
+};

Maybe this should go in a common amlogic-t7-u-boot dts instead of something board-specific?

Quoted 58 lines
board/amlogic/vim4/MAINTAINERS new file +7 -0
new file mode 100644
index 00000000000..5e1ec98b571
@@ -0,0 +1,7 @@
+VIM4
+M:	Lucas Tanure <[email protected]>
+S:	Maintained
+L:	[email protected]
+F:	board/amlogic/vim4/
+F:	configs/khadas-vim4_defconfig
+F:	arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi
board/amlogic/vim4/Makefile new file +4 -0
new file mode 100644
index 00000000000..0cc4078c549
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0+
+# (C) Copyright 2026 Lucas Tanure <[email protected]>
+
+obj-y	:= vim4.o
board/amlogic/vim4/vim4.c new file +14 -0
new file mode 100644
index 00000000000..5db3deefe0e
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2026 Lucas Tanure <[email protected]>
+ */
+
+#include <init.h>
+#include <asm/arch/eth.h>
+
+int misc_init_r(void)
+{
+	meson_generate_serial_ethaddr();
+
+	return 0;
+}
configs/khadas-vim4_defconfig new file +9 -0
new file mode 100644
index 00000000000..10a64c07a88
@@ -0,0 +1,27 @@
+CONFIG_ARM=y
+CONFIG_POSITION_INDEPENDENT=y
+CONFIG_ARCH_MESON=y
+CONFIG_TEXT_BASE=0x00000000
+CONFIG_NR_DRAM_BANKS=1
+CONFIG_ENV_SIZE=0x2000
+CONFIG_DM_GPIO=y
+CONFIG_DEFAULT_DEVICE_TREE="amlogic/amlogic-t7-a311d2-khadas-vim4"
+CONFIG_OF_LIBFDT_OVERLAY=y

configs/khadas-vim4_defconfig line 19

Quoted 10 lines
configs/khadas-vim4_defconfig new file +10 -0
+CONFIG_MESON_T7=y
+CONFIG_SYS_LOAD_ADDR=0x10000000
+CONFIG_DEBUG_UART_BASE=0xfe078000
+CONFIG_DEBUG_UART_CLOCK=24000000
+CONFIG_IDENT_STRING=" khadas-vim4"
+CONFIG_DEBUG_UART=y
+CONFIG_OF_BOARD_SETUP=y
+# CONFIG_DISPLAY_CPUINFO is not set
+# CONFIG_DISPLAY_BOARDINFO is not set
+CONFIG_SYS_PROMPT="kvim4> "

Leave this unset

Quoted 10 lines
configs/khadas-vim4_defconfig new file +8 -0
+# CONFIG_CMD_BDI is not set
+# CONFIG_CMD_IMI is not set
+CONFIG_CMD_CACHE=y
+CONFIG_OF_CONTROL=y
+CONFIG_BAUDRATE=921600
+CONFIG_DEBUG_UART_ANNOUNCE=y
+CONFIG_DEBUG_UART_SKIP_INIT=y
+CONFIG_MESON_SERIAL=y
Signature · 1 line
2.55.0

Best regards,
Ferass

#3 lore raw

Re: [PATCH 1/4] serial: meson: add Amlogic S4 UART support

In reply to Ferass El Hafidi
Quoted 15 lines · Ferass El Hafidi
Quoted 14 lines · Lucas Tanure via groups.io

The S4-generation UART (S4, T7, ...) derives its baud rate from the 24 MHz crystal divided by 2, selected via the XTAL_DIV2 bit in the baud rate register, while older SoCs divide the crystal by 3. Add the "amlogic,meson-s4-uart" compatible with driver data selecting the div-by-2 scheme, matching the Linux driver (meson_s4_uart_data) and the configuration the vendor BL2 programs on T7 hardware.

Older SoCs keep the existing div-by-3 behaviour: Linux also uses div-by-2 on G12A, but both modes work there and switching would risk regressing boards that have shipped with div-by-3 for years.

Also drain the transmitter before changing the baud rate so in-flight characters are not garbled, as the Linux driver does.

Quoted 7 lines
Quoted 1 line
Assisted-by Claude:claude-fable-5

As I understand it, LLM-assisted patches are not welcome in U-Boot right
now: https://lore.kernel.org/u-boot/20260515220758.GM1858239@bill-the-cat/

AFAIK there isn't an official AI policy yet, but it seems the concensus on that matter is currently "please don't". Sorry.

Ok, I will drop this line.

Quoted 134 lines
Quoted 131 lines

---
drivers/serial/serial_meson.c | 51 ++++++++++++++++++++++++++---------

1 file changed, 38 insertions(+), 13 deletions(-)
drivers/serial/serial_meson.c +13 -2
index cc71381f87e..d909fedcfc4 100644
@@ -62,26 +62,49 @@ struct meson_serial_plat {
 #define AML_UART_REG5_USE_NEW_BAUD    BIT(23) /* default 1 (use new baud rate register) */
 #define AML_UART_REG5_BAUD_MASK        0x7fffff
 
+/* Driver data flags */
+#define MESON_UART_XTAL_DIV2    BIT(0)
+
 #if CONFIG_IS_ENABLED(DM_SERIAL)
-static u32 meson_calc_baud_divisor(ulong src_rate, u32 baud)
+static u32 meson_uart_xtal_div(struct udevice *dev)
+{
+    /*
+     * S4-generation UARTs (S4, T7, ...) derive the baud rate from the
+     * crystal divided by 2, older ones divide by 3.
+     */
+    return (dev_get_driver_data(dev) & MESON_UART_XTAL_DIV2) ? 2 : 3;
+}
+
+static u32 meson_calc_baud_divisor(struct udevice *dev, ulong 
 src_rate, u32 baud)
 {
     /*
      * Usually src_rate is 24 MHz (from crystal) as clock source for serial
-     * device. Since 8 Mb/s is the maximum supported baud rate, use 

div by 3
-     * to derive baud rate. This choice is used also in meson_serial_setbrg.
+     * device. Since 8 Mb/s is the maximum supported baud rate, use a +     * divided crystal to derive the baud rate. This choice is used also in
+     * meson_serial_setbrg.
     */
-    return DIV_ROUND_CLOSEST(src_rate / 3, baud) - 1;
+    return DIV_ROUND_CLOSEST(src_rate / meson_uart_xtal_div(dev), baud) - 1;
}

-static void meson_serial_set_baud(struct meson_uart *uart, ulong src_rate, u32 baud)
+static void meson_serial_set_baud(struct udevice *dev, struct meson_uart *uart,
+                  ulong src_rate, u32 baud)
{
    /*
-     * Set crystal divided by 3 (regardless of device tree clock property)
+     * Set the divided crystal (regardless of device tree clock property)
     * as clock source and the corresponding divisor to approximate baud */
-    u32 divisor = meson_calc_baud_divisor(src_rate, baud); +    u32 divisor = meson_calc_baud_divisor(dev, src_rate, baud); u32 val = AML_UART_REG5_USE_XTAL_CLK | AML_UART_REG5_USE_NEW_BAUD | (divisor & AML_UART_REG5_BAUD_MASK);

drivers/serial/serial_meson.c +6 -0
+
+    if (meson_uart_xtal_div(dev) == 2)
+        val |= AML_UART_REG5_XTAL_DIV2;
+
+    /* Drain the transmitter before changing the baud rate */
+    while ((readl(&uart->status) & (AML_UART_TX_EMPTY | 

AML_UART_XMIT_BUSY))
+           != AML_UART_TX_EMPTY)
+        ;
+
    writel(val, &uart->reg5);
}

drivers/serial/serial_meson.c +3 -3
@@ -109,7 +132,7 @@ static int meson_serial_probe(struct udevice *dev)
         return ret;
     ulong rate = clk_get_rate(&per_clk);
 
-    meson_serial_set_baud(uart, rate, CONFIG_BAUDRATE);
+    meson_serial_set_baud(dev, uart, rate, CONFIG_BAUDRATE);
     meson_serial_init(uart);
 
     return 0;
@@ -165,8 +188,9 @@ static int meson_serial_setbrg(struct udevice 
 *dev, const int baud)
 {
     /*
      * Change device baud rate if baud is reasonable (considering a 23 bit
-     * counter with an 8 MHz clock input) and the actual baud
-     * rate is within 2% of the requested value (2% is arbitrary).
+     * counter with an 8 MHz, or 12 MHz for XTAL_DIV2 devices, clock 
 input)
+     * and the actual baud rate is within 2% of the requested value 

(2% is
+     * arbitrary).
     */
    if (baud < 1 || baud > 8000000)
        return -EINVAL;

drivers/serial/serial_meson.c +3 -3
@@ -179,14 +203,14 @@ static int meson_serial_setbrg(struct udevice 
 *dev, const int baud)
     if (ret)
         return ret;
     ulong rate = clk_get_rate(&per_clk);
-    u32 divisor = meson_calc_baud_divisor(rate, baud);
-    u32 calc_baud = (rate / 3) / (divisor + 1);
+    u32 divisor = meson_calc_baud_divisor(dev, rate, baud);
+    u32 calc_baud = (rate / meson_uart_xtal_div(dev)) / (divisor + 1);
     u32 calc_err = baud > calc_baud ? baud - calc_baud : calc_baud - baud;
 
     if (((calc_err * 100) / baud) > 2)
         return -EINVAL;
 
-    meson_serial_set_baud(uart, rate, baud);
+    meson_serial_set_baud(dev, uart, rate, baud);
 
     return 0;

}

drivers/serial/serial_meson.c +1 -0
@@ -244,6 +268,7 @@ static const struct udevice_id meson_serial_ids[] = {
     { .compatible = "amlogic,meson-uart" },
     { .compatible = "amlogic,meson-gx-uart" },
     { .compatible = "amlogic,meson-a1-uart" },
+    { .compatible = "amlogic,meson-s4-uart", .data = 
 MESON_UART_XTAL_DIV2 },
     { }
 };
Signature · 2 lines
-- 
2.55.0

Best regards,
Ferass

#4 lore raw

Re: [PATCH 1/4] serial: meson: add Amlogic S4 UART support

(didn't mean for this to be off-list sorry about that)

Quoted 14 lines · Lucas Tanure
Quoted 13 lines · Ferass El Hafidi
Quoted 11 lines · On Thu, 06 Aug 2026 10:18, "Lucas Tanure via groups.io"=C2=A0…

The S4-generation UART (S4, T7, ...) derives its baud rate from the 24 MHz crystal divided by 2, selected via the XTAL_DIV2 bit in the baud rate register, while older SoCs divide the crystal by 3. Add the "amlogic,meson-s4-uart" compatible with driver data selecting the div-by-2 scheme, matching the Linux driver (meson_s4_uart_data) and the configuration the vendor BL2 programs on T7 hardware.

Older SoCs keep the existing div-by-3 behaviour: Linux also uses div-by-2 on G12A, but both modes work there and switching would risk regressing boards that have shipped with div-by-3 for years.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Also drain the transmitter before changing the baud rate so in-flight characters are not garbled, as the Linux driver does.

Assisted-by Claude:claude-fable-5

=C2=A0
As I understand it, LLM-assisted patches are not welcome in U-Boot rig=

ht

Quoted 1 line
Quoted 1 line

now: https://lore.kernel.org/u-boot/20260515220758.GM1858239@bill-the-=

cat/

Quoted 2 lines
Quoted 2 lines

=C2=A0
AFAIK there isn't an official AI policy yet, but it seems the concensu=

s

Quoted 4 lines
Quoted 1 line

on that matter is currently "please don't". Sorry.

Ok, I will drop this line.

Please do not drop this line. I appreciate the transparency towards your use of AI. I would wait for someone more knowlegable about AI use discussions to reply.

Best regards,
Ferass

#5 lore raw

Re: [PATCH 1/4] serial: meson: add Amlogic S4 UART support

Quoted 30 lines · Ferass El Hafidi

(didn't mean for this to be off-list sorry about that)

Quoted 14 lines · Lucas Tanure
Quoted 13 lines · Ferass El Hafidi
Quoted 11 lines · On Thu, 06 Aug 2026 10:18, "Lucas Tanure via groups.io"=C2=A0…

The S4-generation UART (S4, T7, ...) derives its baud rate from the 24 MHz crystal divided by 2, selected via the XTAL_DIV2 bit in the baud rate register, while older SoCs divide the crystal by 3. Add the "amlogic,meson-s4-uart" compatible with driver data selecting the div-by-2 scheme, matching the Linux driver (meson_s4_uart_data) and the configuration the vendor BL2 programs on T7 hardware.

Older SoCs keep the existing div-by-3 behaviour: Linux also uses div-by-2 on G12A, but both modes work there and switching would risk regressing boards that have shipped with div-by-3 for years.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Also drain the transmitter before changing the baud rate so in-flight characters are not garbled, as the Linux driver does.

Assisted-by Claude:claude-fable-5

=C2=A0
As I understand it, LLM-assisted patches are not welcome in U-Boot rig=

ht

Quoted 1 line
Quoted 1 line

now: https://lore.kernel.org/u-boot/20260515220758.GM1858239@bill-the-=

cat/

Quoted 2 lines
Quoted 2 lines

=C2=A0
AFAIK there isn't an official AI policy yet, but it seems the concensu=

s

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

on that matter is currently "please don't". Sorry.

Ok, I will drop this line.

Please do not drop this line. I appreciate the transparency towards your use of AI. I would wait for someone more knowlegable about AI use discussions to reply.

Ok, I will reply with v2 with all comments fixes and keeping the Ai line. And I wait for the Ai talk.

Quoted 2 lines

Best regards,
Ferass

Thanks
Lucas