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 <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/87667
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yidi Lin <yidilin@google.com>
This commit is contained in:
Yu-Ping Wu 2025-05-14 17:53:25 +08:00 committed by Yidi Lin
commit 65523e98a6
11 changed files with 50 additions and 44 deletions

View file

@ -0,0 +1,21 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <soc/dpm_common.h>
#include <soc/mcu_common.h>
#include <soc/symbols.h>
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;
}

View file

@ -6,7 +6,6 @@
#include <soc/dpm_v1.h>
#include <soc/dramc_soc.h>
#include <soc/spm.h>
#include <soc/symbols.h>
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);
}

View file

@ -3,7 +3,6 @@
#include <device/mmio.h>
#include <soc/dpm_v1.h>
#include <soc/mcu_common.h>
#include <soc/symbols.h>
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())

View file

@ -3,7 +3,6 @@
#include <device/mmio.h>
#include <soc/dpm_v2.h>
#include <soc/mcu_common.h>
#include <soc/symbols.h>
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);

View file

@ -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 <soc/mcu_common.h>
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__ */

View file

@ -4,7 +4,7 @@
#define __SOC_MEDIATEK_COMMON_DPM_V1_H__
#include <soc/addressmap.h>
#include <soc/mcu_common.h>
#include <soc/dpm_common.h>
#include <types.h>
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__ */

View file

@ -4,7 +4,7 @@
#define __SOC_MEDIATEK_COMMON_DPM_V2_H__
#include <soc/addressmap.h>
#include <soc/mcu_common.h>
#include <soc/dpm_common.h>
#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__ */

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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