From 4c22c3d83e7fa68e706f4533685e983583c56b53 Mon Sep 17 00:00:00 2001 From: Jarried Lin Date: Tue, 15 Apr 2025 13:35:54 +0800 Subject: [PATCH] soc/mediatek/mt8196: Add DCC driver support in ramstage Duty Cycle Correlation (DCC) analyzes and optimizes the relationship between the duty cycles of multiple signals. This commit implements DCC driver support to improve clock signals, power management, and communication systems, enhancing system stability and performance. These improvements will become more significant as the SoC ages. BUG=b:389784352 BRANCH=rauru TEST=Build pass, check dcc log: [DEBUG] [DCC] DSU=0x0, LCPU=0x0, MCPU=0x17, BCPU=0x1b Change-Id: I77e5cd951f45dad7a6e2e77c135b821e4179e019 Signed-off-by: Jarried Lin Reviewed-on: https://review.coreboot.org/c/coreboot/+/87320 Reviewed-by: Paul Menzel Reviewed-by: Yidi Lin Tested-by: build bot (Jenkins) Reviewed-by: Yu-Ping Wu --- src/soc/mediatek/mt8196/Makefile.mk | 1 + src/soc/mediatek/mt8196/dcc.c | 23 +++++++++++++++++++++++ src/soc/mediatek/mt8196/include/soc/dcc.h | 15 +++++++++++++++ src/soc/mediatek/mt8196/soc.c | 2 ++ 4 files changed, 41 insertions(+) create mode 100644 src/soc/mediatek/mt8196/dcc.c create mode 100644 src/soc/mediatek/mt8196/include/soc/dcc.h diff --git a/src/soc/mediatek/mt8196/Makefile.mk b/src/soc/mediatek/mt8196/Makefile.mk index 9d05ee46ea..93be1b434b 100644 --- a/src/soc/mediatek/mt8196/Makefile.mk +++ b/src/soc/mediatek/mt8196/Makefile.mk @@ -55,6 +55,7 @@ romstage-y += thermal.c romstage-y += thermal_sram.c ramstage-$(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE) += ../common/bl31.c +ramstage-y += dcc.c ramstage-y += ddp.c ramstage-y += ../common/display.c ramstage-y += ../common/dpm_v2.c diff --git a/src/soc/mediatek/mt8196/dcc.c b/src/soc/mediatek/mt8196/dcc.c new file mode 100644 index 0000000000..13a621c5b3 --- /dev/null +++ b/src/soc/mediatek/mt8196/dcc.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#include +#include +#include + +void dcc_init(void) +{ + /* DSU */ + clrbits32p(BUS_PLLDIV_CFG1, GENMASK(20, 16)); + /* LCPU */ + clrbits32p(CPU_PLLDIV_0_CFG1, GENMASK(20, 16)); + /* MCPU */ + clrsetbits32p(CPU_PLLDIV_1_CFG1, GENMASK(20, 16), BIT(20) | GENMASK(18, 16)); + /* BCPU */ + clrsetbits32p(CPU_PLLDIV_2_CFG1, GENMASK(20, 16), GENMASK(17, 16) | GENMASK(20, 19)); + + printk(BIOS_DEBUG, "[DCC] DSU=%#x, LCPU=%#x, MCPU=%#x, BCPU=%#x\n", + (read32p(BUS_PLLDIV_CFG1) >> 16) & 0x1F, + (read32p(CPU_PLLDIV_0_CFG1) >> 16) & 0x1F, + (read32p(CPU_PLLDIV_1_CFG1) >> 16) & 0x1F, + (read32p(CPU_PLLDIV_2_CFG1) >> 16) & 0x1F); +} diff --git a/src/soc/mediatek/mt8196/include/soc/dcc.h b/src/soc/mediatek/mt8196/include/soc/dcc.h new file mode 100644 index 0000000000..3aba1f1d1c --- /dev/null +++ b/src/soc/mediatek/mt8196/include/soc/dcc.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#ifndef SOC_MEDIATEK_MT8196_DCC_H +#define SOC_MEDIATEK_MT8196_DCC_H + +#include + +#define BUS_PLLDIV_CFG1 (MCUSYS_BASE + 0x0104) /* DSU */ +#define CPU_PLLDIV_0_CFG1 (MCUSYS_BASE + 0x0110) /* LCPU */ +#define CPU_PLLDIV_1_CFG1 (MCUSYS_BASE + 0x011C) /* MCPU */ +#define CPU_PLLDIV_2_CFG1 (MCUSYS_BASE + 0x0128) /* BCPU */ + +void dcc_init(void); + +#endif /* SOC_MEDIATEK_MT8196_DCC_H */ diff --git a/src/soc/mediatek/mt8196/soc.c b/src/soc/mediatek/mt8196/soc.c index 2d32bc3d45..c5a83d0c73 100644 --- a/src/soc/mediatek/mt8196/soc.c +++ b/src/soc/mediatek/mt8196/soc.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,7 @@ static void soc_init(struct device *dev) { uint32_t storage_type = mainboard_get_storage_type(); + dcc_init(); mtk_fsp_init(RAMSTAGE_SOC_INIT); mtk_fsp_add_param(FSP_PARAM_TYPE_STORAGE, sizeof(storage_type), &storage_type); add_pi_image_params();