Yidi Lin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/47897 )
Change subject: WIP: mediatek/mt8192/spm.c: Use mtlib_load_and_run API ......................................................................
WIP: mediatek/mt8192/spm.c: Use mtlib_load_and_run API
Signed-off-by: Yidi Lin yidi.lin@mediatek.com Change-Id: Ie40e5b62bbaa738cd38312563e81a23443044a64 --- M src/soc/mediatek/mt8192/spm.c 1 file changed, 32 insertions(+), 26 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/97/47897/1
diff --git a/src/soc/mediatek/mt8192/spm.c b/src/soc/mediatek/mt8192/spm.c index b2d2d47..5e879ab 100644 --- a/src/soc/mediatek/mt8192/spm.c +++ b/src/soc/mediatek/mt8192/spm.c @@ -5,11 +5,13 @@ #include <console/console.h> #include <delay.h> #include <device/mmio.h> +#include <soc/mtlib_common.h> #include <soc/spm.h> #include <soc/symbols.h> #include <timer.h>
#define SPMFW_HEADER_SIZE 16 +#define SPM_FW_FILE "spm_firmware.bin"
static struct pwr_ctrl spm_init_ctrl = { /* Auto-gen Start */ @@ -491,22 +493,14 @@ write32(&mtk_spm->pcm_pwr_io_en, 0); }
-static int spm_load_firmware(struct dyna_load_pcm *pcm) +static void spm_parse_firmware(struct mtlib_fw_prop *fw) { - struct stopwatch sw; - const char *file_name = "spm_firmware.bin"; size_t file_size, copy_size; int offset; u16 firmware_size;
- stopwatch_init(&sw); - - file_size = cbfs_boot_load_file(file_name, _dram_dma, - REGION_SIZE(dram_dma), CBFS_TYPE_RAW); - if (file_size == 0) { - printk(BIOS_ERR, "SPM binary %s not found\n", file_name); - return -1; - } + struct dyna_load_pcm *pcm = (struct dyna_load_pcm *)fw->priv; + file_size = fw->size;
/* * spmfw layout: @@ -519,28 +513,25 @@ /* firmware size */ offset = 0; copy_size = sizeof(firmware_size); - memcpy(&firmware_size, _dram_dma + offset, copy_size); + memcpy(&firmware_size, fw->buf + offset, copy_size); printk(BIOS_DEBUG, "SPM: binary array size = %#x\n", firmware_size);
/* binary */ offset = SPMFW_HEADER_SIZE; /* binary start offset */ copy_size = firmware_size * sizeof(u32); assert(offset < file_size); - pcm->buf = (u8 *)(_dram_dma + offset); + pcm->buf = (u8 *)(fw->buf + offset);
/* descriptor */ offset += copy_size; assert(offset < file_size); copy_size = sizeof(pcm->desc); - memcpy(&pcm->desc, _dram_dma + offset, copy_size); + memcpy(&pcm->desc, fw->buf + offset, copy_size);
/* version */ offset += copy_size; assert(offset < file_size); - printk(BIOS_INFO, "spmfw (version %s) loaded in %ld msecs\n", - _dram_dma + offset, stopwatch_duration_msecs(&sw)); - - return 0; + printk(BIOS_INFO, "SPM: spmfw (version %s)\n", (u8 *)fw->buf + offset); }
static void spm_set_wakeup_event(struct pwr_ctrl *pwrctrl) @@ -637,6 +628,23 @@ udelay(SPM_INIT_DONE_US); }
+static void reset_spm(struct mtlib_fw_prop *fw) +{ + struct dyna_load_pcm *pcm = (struct dyna_load_pcm *)fw->priv; + + spm_parse_firmware(fw); + spm_reset_and_init_pcm(); + spm_kick_im_to_fetch(pcm); + spm_init_pcm_register(); + spm_set_wakeup_event(&spm_init_ctrl); + spm_kick_pcm_to_run(&spm_init_ctrl); +} + +static struct mtlib_fw_prop spm = { + .name = SPM_FW_FILE, + .reset = reset_spm, +}; + int spm_init(void) { struct dyna_load_pcm pcm; @@ -648,17 +656,15 @@ spm_set_power_control(&spm_init_ctrl); spm_set_sysclk_settle();
- if (spm_load_firmware(&pcm)) { - printk(BIOS_ERR, "SPM: firmware is not ready\n"); + spm.buf = _dram_dma; + spm.buf_size = REGION_SIZE(dram_dma); + spm.priv = (void *)&pcm; + + if (mtlib_load_and_run(&spm)) { + printk(BIOS_ERR, "%s() failed\n", __func__); return -1; }
- spm_reset_and_init_pcm(); - spm_kick_im_to_fetch(&pcm); - spm_init_pcm_register(); - spm_set_wakeup_event(&spm_init_ctrl); - spm_kick_pcm_to_run(&spm_init_ctrl); - printk(BIOS_INFO, "SPM: %s done in %ld msecs, spm pc = %#x\n", __func__, stopwatch_duration_msecs(&sw), read32(&mtk_spm->md32pcm_pc));