From 65523e98a6700dc9c590fcdb49748a47079661bf Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Wed, 14 May 2025 17:53:25 +0800 Subject: [PATCH] soc/mediatek: Extract DPM common code Move function declarations to dpm_common.h, which is shared for both dpm_v1 and dpm_v2. Add a new function dpm_init_mcu() to the header to reduce duplicate code in dpm_v1.c, dpm_v2.c and dpm_4ch.c. BUG=none TEST=emerge-skywalker coreboot BRANCH=none Change-Id: I8d6318e9c3c4570cb8f3ff64242fc414770db653 Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/87667 Tested-by: build bot (Jenkins) Reviewed-by: Yidi Lin --- src/soc/mediatek/common/dpm.c | 21 +++++++++++++++++++ src/soc/mediatek/common/dpm_4ch.c | 15 ++----------- src/soc/mediatek/common/dpm_v1.c | 14 +++---------- src/soc/mediatek/common/dpm_v2.c | 13 +++--------- .../mediatek/common/include/soc/dpm_common.h | 15 +++++++++++++ src/soc/mediatek/common/include/soc/dpm_v1.h | 7 +------ src/soc/mediatek/common/include/soc/dpm_v2.h | 5 +---- src/soc/mediatek/mt8188/Makefile.mk | 1 + src/soc/mediatek/mt8192/Makefile.mk | 1 + src/soc/mediatek/mt8195/Makefile.mk | 1 + src/soc/mediatek/mt8196/Makefile.mk | 1 + 11 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 src/soc/mediatek/common/dpm.c create mode 100644 src/soc/mediatek/common/include/soc/dpm_common.h diff --git a/src/soc/mediatek/common/dpm.c b/src/soc/mediatek/common/dpm.c new file mode 100644 index 0000000000..5a2c6e9d9a --- /dev/null +++ b/src/soc/mediatek/common/dpm.c @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +int dpm_init_mcu(struct mtk_mcu *mcu_list) +{ + struct mtk_mcu *mcu = mcu_list; + + while (mcu->firmware_name) { + mcu->load_buffer = _dram_dma; + mcu->buffer_size = REGION_SIZE(dram_dma); + if (mtk_init_mcu(mcu)) + return -1; + + mcu++; + } + + return 0; +} diff --git a/src/soc/mediatek/common/dpm_4ch.c b/src/soc/mediatek/common/dpm_4ch.c index 6b15411300..e4be08b08a 100644 --- a/src/soc/mediatek/common/dpm_4ch.c +++ b/src/soc/mediatek/common/dpm_4ch.c @@ -6,7 +6,6 @@ #include #include #include -#include static struct dpm_regs *const mtk_dpm2 = (void *)DPM_CFG_BASE2; @@ -62,6 +61,7 @@ static struct mtk_mcu dpm_mcu_4ch[] = { .priv = mtk_dpm2, .reset = dpm_reset, }, + {}, }; int dpm_4ch_init(void) @@ -74,16 +74,5 @@ int dpm_4ch_init(void) int dpm_4ch_para_setting(void) { - int i; - struct mtk_mcu *dpm; - - for (i = 0; i < ARRAY_SIZE(dpm_mcu_4ch); i++) { - dpm = &dpm_mcu_4ch[i]; - dpm->load_buffer = _dram_dma; - dpm->buffer_size = REGION_SIZE(dram_dma); - if (mtk_init_mcu(dpm)) - return -1; - } - - return 0; + return dpm_init_mcu(dpm_mcu_4ch); } diff --git a/src/soc/mediatek/common/dpm_v1.c b/src/soc/mediatek/common/dpm_v1.c index 4691b35569..d059d02a80 100644 --- a/src/soc/mediatek/common/dpm_v1.c +++ b/src/soc/mediatek/common/dpm_v1.c @@ -3,7 +3,6 @@ #include #include #include -#include static struct mtk_mcu dpm_mcu[] = { { @@ -16,6 +15,7 @@ static struct mtk_mcu dpm_mcu[] = { .priv = mtk_dpm, .reset = dpm_reset, }, + {}, }; void dpm_reset(struct mtk_mcu *mcu) @@ -32,9 +32,6 @@ void dpm_reset(struct mtk_mcu *mcu) int dpm_init(void) { - int i; - struct mtk_mcu *dpm; - if (CONFIG(DPM_FOUR_CHANNEL)) if (dpm_4ch_init()) return -1; @@ -42,13 +39,8 @@ int dpm_init(void) /* config DPM SRAM layout */ clrsetbits32(&mtk_dpm->sw_rstn, DPM_MEM_RATIO_MASK, DPM_MEM_RATIO_CFG1); - for (i = 0; i < ARRAY_SIZE(dpm_mcu); i++) { - dpm = &dpm_mcu[i]; - dpm->load_buffer = _dram_dma; - dpm->buffer_size = REGION_SIZE(dram_dma); - if (mtk_init_mcu(dpm)) - return -1; - } + if (dpm_init_mcu(dpm_mcu)) + return -1; if (CONFIG(DPM_FOUR_CHANNEL)) if (dpm_4ch_para_setting()) diff --git a/src/soc/mediatek/common/dpm_v2.c b/src/soc/mediatek/common/dpm_v2.c index b0f0dbcb88..4df8bd0e13 100644 --- a/src/soc/mediatek/common/dpm_v2.c +++ b/src/soc/mediatek/common/dpm_v2.c @@ -3,7 +3,6 @@ #include #include #include -#include static struct mtk_mcu dpm_mcu[] = { { @@ -15,6 +14,7 @@ static struct mtk_mcu dpm_mcu[] = { .run_address = (void *)DPM_PM_SRAM_BASE, .reset = dpm_reset, }, + {}, }; void dpm_reset(struct mtk_mcu *mcu) @@ -25,19 +25,12 @@ void dpm_reset(struct mtk_mcu *mcu) int dpm_init(void) { - int i; - struct mtk_mcu *dpm; u32 dramc_wbr_backup = read32p(DRAMC_WBR); setbits32p(DRAMC_WBR, ENABLE_DRAMC_WBR_MASK); - for (i = 0; i < ARRAY_SIZE(dpm_mcu); i++) { - dpm = &dpm_mcu[i]; - dpm->load_buffer = _dram_dma; - dpm->buffer_size = REGION_SIZE(dram_dma); - if (mtk_init_mcu(dpm)) - return -1; - } + if (dpm_init_mcu(dpm_mcu)) + return -1; write32p(DRAMC_WBR, dramc_wbr_backup); diff --git a/src/soc/mediatek/common/include/soc/dpm_common.h b/src/soc/mediatek/common/include/soc/dpm_common.h new file mode 100644 index 0000000000..75833151fb --- /dev/null +++ b/src/soc/mediatek/common/include/soc/dpm_common.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __SOC_MEDIATEK_COMMON_DPM_COMMON_H__ +#define __SOC_MEDIATEK_COMMON_DPM_COMMON_H__ + +#include + +void dpm_reset(struct mtk_mcu *mcu); +int dpm_init_mcu(struct mtk_mcu *mcu_list); +int dpm_init(void); + +int dpm_4ch_para_setting(void); +int dpm_4ch_init(void); + +#endif /* __SOC_MEDIATEK_COMMON_DPM_COMMON_H__ */ diff --git a/src/soc/mediatek/common/include/soc/dpm_v1.h b/src/soc/mediatek/common/include/soc/dpm_v1.h index 65623a2671..0f23b5b36f 100644 --- a/src/soc/mediatek/common/include/soc/dpm_v1.h +++ b/src/soc/mediatek/common/include/soc/dpm_v1.h @@ -4,7 +4,7 @@ #define __SOC_MEDIATEK_COMMON_DPM_V1_H__ #include -#include +#include #include struct dpm_regs { @@ -48,9 +48,4 @@ check_member(dpm_regs, status_4, 0x70B0); static struct dpm_regs *const mtk_dpm = (void *)DPM_CFG_BASE; -void dpm_reset(struct mtk_mcu *mcu); -int dpm_init(void); -int dpm_4ch_para_setting(void); -int dpm_4ch_init(void); - #endif /* __SOC_MEDIATEK_COMMON_DPM_V1_H__ */ diff --git a/src/soc/mediatek/common/include/soc/dpm_v2.h b/src/soc/mediatek/common/include/soc/dpm_v2.h index c11a9bb2da..1588622d67 100644 --- a/src/soc/mediatek/common/include/soc/dpm_v2.h +++ b/src/soc/mediatek/common/include/soc/dpm_v2.h @@ -4,7 +4,7 @@ #define __SOC_MEDIATEK_COMMON_DPM_V2_H__ #include -#include +#include #define DPM_RST_OFFSET 0x7074 #define DPM_SW_RSTN BIT(0) @@ -16,7 +16,4 @@ #define ENABLE_DRAMC_WBR_MASK 0x2ffff -void dpm_reset(struct mtk_mcu *mcu); -int dpm_init(void); - #endif /* __SOC_MEDIATEK_COMMON_DPM_V2_H__ */ diff --git a/src/soc/mediatek/mt8188/Makefile.mk b/src/soc/mediatek/mt8188/Makefile.mk index e28c50d02e..3c77664cfc 100644 --- a/src/soc/mediatek/mt8188/Makefile.mk +++ b/src/soc/mediatek/mt8188/Makefile.mk @@ -41,6 +41,7 @@ ramstage-y += ../common/dfd.c ramstage-y += ../common/display.c ramstage-y += ../common/dp/dptx_common.c ../common/dp/dptx_hal_common.c ramstage-y += ../common/dp/dp_intf.c ../common/dp/dptx.c ../common/dp/dptx_hal.c dp_intf.c +ramstage-y += ../common/dpm.c ramstage-y += ../common/dpm_v1.c ramstage-$(CONFIG_DPM_FOUR_CHANNEL) += ../common/dpm_4ch.c ramstage-y += ../common/dsi.c ../common/mtk_mipi_dphy.c diff --git a/src/soc/mediatek/mt8192/Makefile.mk b/src/soc/mediatek/mt8192/Makefile.mk index 90a4e6d807..a92584da0b 100644 --- a/src/soc/mediatek/mt8192/Makefile.mk +++ b/src/soc/mediatek/mt8192/Makefile.mk @@ -38,6 +38,7 @@ ramstage-$(CONFIG_ARM64_USE_ARM_TRUSTED_FIRMWARE) += ../common/bl31.c ramstage-y += ../common/ddp.c ddp.c ramstage-y += devapc.c ramstage-y += ../common/dfd.c +ramstage-y += ../common/dpm.c ramstage-y += ../common/dpm_v1.c ramstage-y += ../common/dsi.c ../common/mtk_mipi_dphy.c ramstage-y += ../common/l2c_ops.c diff --git a/src/soc/mediatek/mt8195/Makefile.mk b/src/soc/mediatek/mt8195/Makefile.mk index 5e4e98f121..b960f8955b 100644 --- a/src/soc/mediatek/mt8195/Makefile.mk +++ b/src/soc/mediatek/mt8195/Makefile.mk @@ -48,6 +48,7 @@ ramstage-y += ../common/ddp.c ddp.c ramstage-y += ../common/devapc.c devapc.c ramstage-y += ../common/dfd.c ramstage-y += ../common/display.c +ramstage-y += ../common/dpm.c ramstage-y += ../common/dpm_v1.c ramstage-$(CONFIG_DPM_FOUR_CHANNEL) += ../common/dpm_4ch.c ramstage-y += ../common/dp/dptx_common.c ../common/dp/dptx_hal_common.c diff --git a/src/soc/mediatek/mt8196/Makefile.mk b/src/soc/mediatek/mt8196/Makefile.mk index 5d6e1db74d..17c768fb37 100644 --- a/src/soc/mediatek/mt8196/Makefile.mk +++ b/src/soc/mediatek/mt8196/Makefile.mk @@ -58,6 +58,7 @@ 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.c ramstage-y += ../common/dpm_v2.c ramstage-y += ../common/dp/dptx_common.c ../common/dp/dptx_hal_common.c ramstage-y += dptx.c dptx_hal.c dp_intf.c