On 3/10/26 7:16 PM, David Lechner wrote:
> From: Chris-QJ Chen <[email protected]>
>
> Add TARGET_MT8189 for MT8189 and similar SoCs.
>
> Signed-off-by: Chris-QJ Chen <[email protected]>
> Signed-off-by: Macpaul Lin <[email protected]>
> Reviewed-by: Macpaul Lin <[email protected]>
> Signed-off-by: David Lechner <[email protected]>
> ---
> arch/arm/mach-mediatek/Kconfig | 11 ++++++-
> arch/arm/mach-mediatek/Makefile | 1 +
> arch/arm/mach-mediatek/mt8189/Makefile | 3 ++
> arch/arm/mach-mediatek/mt8189/init.c | 58
> ++++++++++++++++++++++++++++++++++
> 4 files changed, 72 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-mediatek/Kconfig b/arch/arm/mach-mediatek/Kconfig
> index 671a6cb1cad..b5b06f4e5b2 100644
> --- a/arch/arm/mach-mediatek/Kconfig
> +++ b/arch/arm/mach-mediatek/Kconfig
> @@ -93,6 +93,15 @@ config TARGET_MT8188
> USB3.0 dual role, SD and MMC cards, UFS, PWM, I2C, I2S, S/PDIF, and
> several LPDDR3 and LPDDR4 options.
>
> +config TARGET_MT8189
> + bool "MediaTek MT8189 SoC"
> + select ARM64
> + help
> + The MediaTek MT8189 is a ARM64-based SoC with a dual-core Cortex-A78
> and
> + a six-core Cortex-A55. It is including UART, SPI, USB3.0 dual role,
> + SD and MMC cards, UFS, PWM, I2C, I2S, S/PDIF, and several LPDDR4x
> + and LPDDR5x options.
> +
> config TARGET_MT8195
> bool "MediaTek MT8195 SoC"
> select ARM64
> @@ -201,7 +210,7 @@ config SYS_CONFIG_NAME
> config MTK_BROM_HEADER_INFO
> string
> default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629
> - default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183
> || TARGET_MT8188 || TARGET_MT8195
> + default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183
> || TARGET_MT8188 || TARGET_MT8189 || TARGET_MT8195
> default "lk=1" if TARGET_MT7623
>
> config MTK_TZ_MOVABLE
> diff --git a/arch/arm/mach-mediatek/Makefile b/arch/arm/mach-mediatek/Makefile
> index d1f64d61ab9..35f748a70d6 100644
> --- a/arch/arm/mach-mediatek/Makefile
> +++ b/arch/arm/mach-mediatek/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_TARGET_MT7987) += mt7987/
> obj-$(CONFIG_TARGET_MT7988) += mt7988/
> obj-$(CONFIG_TARGET_MT8183) += mt8183/
> obj-$(CONFIG_TARGET_MT8188) += mt8188/
> +obj-$(CONFIG_TARGET_MT8189) += mt8189/
> obj-$(CONFIG_TARGET_MT8195) += mt8195/
> obj-$(CONFIG_TARGET_MT8365) += mt8365/
> obj-$(CONFIG_TARGET_MT8512) += mt8512/
> diff --git a/arch/arm/mach-mediatek/mt8189/Makefile
> b/arch/arm/mach-mediatek/mt8189/Makefile
> new file mode 100644
> index 00000000000..886ab7e4eb9
> --- /dev/null
> +++ b/arch/arm/mach-mediatek/mt8189/Makefile
> @@ -0,0 +1,3 @@
> +# SPDX-License-Identifier: GPL-2.0
> +
> +obj-y += init.o
> diff --git a/arch/arm/mach-mediatek/mt8189/init.c
> b/arch/arm/mach-mediatek/mt8189/init.c
> new file mode 100644
> index 00000000000..80910810668
> --- /dev/null
> +++ b/arch/arm/mach-mediatek/mt8189/init.c
> @@ -0,0 +1,58 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2026 MediaTek Inc.
> + * Author: Chris-QJ Chen <[email protected]>
> + */
> +
> +#include <fdtdec.h>
> +#include <stdio.h>
> +#include <asm/global_data.h>
> +#include <asm/system.h>
> +#include <linux/sizes.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +int dram_init(void)
> +{
> + int ret;
> +
> + ret = fdtdec_setup_memory_banksize();
Enabling debug messages shows that this is setting
gd->bd->bi_dram[0].start and gd->bd->bi_dram[0].size with
junk values.
```
setup_memory_banksize: DRAM Bank #0: start = 0xe51ff004, size = 0xe51ff004
```
I believe gd->bd has not be assigned yet at this point. And we are
setting these values later in dram_init_banksize() anyway. So we should
be able to drop this call.
> + if (ret)
> + return ret;
> +
> + fdtdec_setup_mem_size_base();
Should check return value here.
> +
> + /*
> + * Limit gd->ram_top not exceeding SZ_4G.
> + * Because some periphals like mmc requires DMA buffer
> + * allocated below SZ_4G.
> + *
> + * Note: SZ_1M is for adjusting gd->relocaddr,
> + * the reserved memory for u-boot itself.
> + */
> + if (gd->ram_base + gd->ram_size >= SZ_4G)
> + gd->mon_len = (gd->ram_base + gd->ram_size + SZ_1M) - SZ_4G;
It looks like this code is not actually acting as the comment says
that it should.
> +
> + return 0;
> +}
The solution should be to replace it with:
phys_size_t get_effective_memsize(void) {
/*
* Limit gd->ram_top not exceeding SZ_4G. Because some peripherals like
* mmc requires DMA buffer allocated below SZ_4G.
*/
return SZ_4G - gd->ram_base;
}
> +
> +int dram_init_banksize(void)
> +{
> + gd->bd->bi_dram[0].start = gd->ram_base;
> + gd->bd->bi_dram[0].size = gd->ram_size;
> +
> + return 0;
> +}
> +
> +void reset_cpu(ulong addr)
> +{
> + if (!CONFIG_IS_ENABLED(SYSRESET))
> + psci_system_reset();
> +}
> +
> +int print_cpuinfo(void)
> +{
> + printf("CPU: MediaTek MT8189\n");
> +
> + return 0;
> +}
>