Add Amlogic T7 (A311D2) and Khadas VIM4 support
Subsystems (3)
PATCH v2 1/4 serial: meson: add Amlogic S4 UART support
In reply to Lucas TanureThe 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.
--- drivers/serial/serial_meson.c | 51 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-)
drivers/serial/serial_meson.c +38 -13
@@ -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
PATCH v2 4/4 doc: board: amlogic: add Khadas VIM4 documentation
In reply to Lucas TanureDocument 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.
--- 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
@@ -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
v2 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.
Changes in v2:
- move the T7 register and reserved memory defines to a new asm/arch-meson/t7.h header
- shorten the MESON_T7 Kconfig help text to match the other SoCs
- drop __maybe_unused from meson_init_reserved_memory(), the parameter is used
- move the SoC-level bootph-all properties to a common amlogic-t7-u-boot.dtsi
- drop CONFIG_SYS_PROMPT from the defconfig
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 | 16 +++ arch/arm/dts/amlogic-t7-u-boot.dtsi | 14 ++ arch/arm/include/asm/arch-meson/boot0.h | 18 +++ arch/arm/include/asm/arch-meson/t7.h | 25 ++++ arch/arm/mach-meson/Kconfig | 9 ++ arch/arm/mach-meson/Makefile | 1 + arch/arm/mach-meson/board-t7.c | 82 ++++++++++++ board/amlogic/vim4/MAINTAINERS | 8 ++ board/amlogic/vim4/Makefile | 4 + board/amlogic/vim4/vim4.c | 14 ++ configs/khadas-vim4_defconfig | 26 ++++ doc/board/amlogic/index.rst | 119 ++++++++--------- doc/board/amlogic/khadas-vim4.rst | 122 ++++++++++++++++++ drivers/serial/serial_meson.c | 51 ++++++-- 14 files changed, 437 insertions(+), 72 deletions(-) create mode 100644 arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi create mode 100644 arch/arm/dts/amlogic-t7-u-boot.dtsi create mode 100644 arch/arm/include/asm/arch-meson/boot0.h create mode 100644 arch/arm/include/asm/arch-meson/t7.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
PATCH v2 2/4 arm: meson: add Amlogic T7 SoC family support
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.
--- arch/arm/include/asm/arch-meson/boot0.h | 18 ++++++ arch/arm/include/asm/arch-meson/t7.h | 25 ++++++++ arch/arm/mach-meson/Kconfig | 9 +++ arch/arm/mach-meson/Makefile | 1 + arch/arm/mach-meson/board-t7.c | 82 +++++++++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 arch/arm/include/asm/arch-meson/boot0.h create mode 100644 arch/arm/include/asm/arch-meson/t7.h create mode 100644 arch/arm/mach-meson/board-t7.c
arch/arm/include/asm/arch-meson/boot0.h new file +18 -0
@@ -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/include/asm/arch-meson/t7.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* (C) Copyright 2026 Lucas Tanure <[email protected]> +*/ + +#ifndef __T7_H__ +#define __T7_H__ + +#include <linux/bitops.h> + +#define T7_WDT_CTRL 0xfe002100 +#define T7_WDT_CTRL_EN BIT(18) + +/* +* 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 the T7 memory map. 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 + +#endif /* __T7_H__ */
arch/arm/mach-meson/Kconfig +9 -0
@@ -67,6 +67,14 @@ 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 an A311D2 + endchoice config SYS_SOC
@@ -91,6 +99,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
@@ -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 +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v2 3/4 board: amlogic: add Khadas VIM4 support
In reply to Lucas TanureAdd 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).
--- .../amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi | 16 ++++++++++++ arch/arm/dts/amlogic-t7-u-boot.dtsi | 14 ++++++++++ board/amlogic/vim4/MAINTAINERS | 7 +++++ board/amlogic/vim4/Makefile | 4 +++ board/amlogic/vim4/vim4.c | 14 ++++++++++ configs/khadas-vim4_defconfig | 26 +++++++++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 arch/arm/dts/amlogic-t7-a311d2-khadas-vim4-u-boot.dtsi create mode 100644 arch/arm/dts/amlogic-t7-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 +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright (c) 2026 Lucas Tanure <[email protected]> + */ + +#include "amlogic-t7-u-boot.dtsi" + +/ { + chosen { + stdout-path = "serial0:921600n8"; + }; +}; + +&xtal { + bootph-all; +};
arch/arm/dts/amlogic-t7-u-boot.dtsi new file +14 -0
@@ -0,0 +1,14 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) +/* + * Copyright (c) 2026 Lucas Tanure <[email protected]> + */ + +/ { + soc { + bootph-all; + }; +}; + +&uart_a { + bootph-all; +};
board/amlogic/vim4/MAINTAINERS new file +7 -0
@@ -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
@@ -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
@@ -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 +26 -0
@@ -0,0 +1,26 @@ +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_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