soc/mediatek/mt8192: Do dram full calibration
If no correct params were found in flash, do dram full calibration. Full calibration will load blob, dram.elf. Blob version: v3, size: 320KB. Signed-off-by: Huayang Duan <huayang.duan@mediatek.com> Change-Id: I2d4437a4e4c770de084927018d4dd3f2e8b87fb1 Reviewed-on: https://review.coreboot.org/c/coreboot/+/44570 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
parent
3ff948651a
commit
68e597d81e
|
@ -37,6 +37,16 @@ ramstage-y += ../common/timer.c
|
||||||
ramstage-y += ../common/uart.c
|
ramstage-y += ../common/uart.c
|
||||||
ramstage-y += ../common/usb.c usb.c
|
ramstage-y += ../common/usb.c usb.c
|
||||||
|
|
||||||
|
MT8192_BLOB_DIR := 3rdparty/blobs/soc/mediatek/mt8192
|
||||||
|
|
||||||
|
DRAM_CBFS := $(CONFIG_CBFS_PREFIX)/dram
|
||||||
|
$(DRAM_CBFS)-file := $(MT8192_BLOB_DIR)/dram.elf
|
||||||
|
$(DRAM_CBFS)-type := stage
|
||||||
|
$(DRAM_CBFS)-compression := $(CBFS_PRERAM_COMPRESS_FLAG)
|
||||||
|
ifneq ($(wildcard $($(DRAM_CBFS)-file)),)
|
||||||
|
cbfs-files-y += $(DRAM_CBFS)
|
||||||
|
endif
|
||||||
|
|
||||||
BL31_MAKEARGS += PLAT=mt8192
|
BL31_MAKEARGS += PLAT=mt8192
|
||||||
|
|
||||||
CPPFLAGS_common += -Isrc/soc/mediatek/mt8192/include
|
CPPFLAGS_common += -Isrc/soc/mediatek/mt8192/include
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <ip_checksum.h>
|
#include <ip_checksum.h>
|
||||||
#include <soc/emi.h>
|
#include <soc/emi.h>
|
||||||
#include <symbols.h>
|
#include <symbols.h>
|
||||||
|
#include <timer.h>
|
||||||
|
|
||||||
static int mt_mem_test(const struct dramc_data *dparam)
|
static int mt_mem_test(const struct dramc_data *dparam)
|
||||||
{
|
{
|
||||||
|
@ -41,7 +42,7 @@ static u32 compute_checksum(const struct dramc_param *dparam)
|
||||||
static int dram_run_fast_calibration(const struct dramc_param *dparam)
|
static int dram_run_fast_calibration(const struct dramc_param *dparam)
|
||||||
{
|
{
|
||||||
if (!is_valid_dramc_param(dparam)) {
|
if (!is_valid_dramc_param(dparam)) {
|
||||||
printk(BIOS_WARNING, "Invalid DRAM calibration data from flash\n");
|
printk(BIOS_WARNING, "DRAM-K: Invalid DRAM calibration data from flash\n");
|
||||||
dump_param_header((void *)dparam);
|
dump_param_header((void *)dparam);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +50,7 @@ static int dram_run_fast_calibration(const struct dramc_param *dparam)
|
||||||
const u32 checksum = compute_checksum(dparam);
|
const u32 checksum = compute_checksum(dparam);
|
||||||
if (dparam->header.checksum != checksum) {
|
if (dparam->header.checksum != checksum) {
|
||||||
printk(BIOS_ERR,
|
printk(BIOS_ERR,
|
||||||
"Invalid DRAM calibration checksum from flash "
|
"DRAM-K: Invalid DRAM calibration checksum from flash "
|
||||||
"(expected: %#x, saved: %#x)\n",
|
"(expected: %#x, saved: %#x)\n",
|
||||||
checksum, dparam->header.checksum);
|
checksum, dparam->header.checksum);
|
||||||
return DRAMC_ERR_INVALID_CHECKSUM;
|
return DRAMC_ERR_INVALID_CHECKSUM;
|
||||||
|
@ -58,13 +59,13 @@ static int dram_run_fast_calibration(const struct dramc_param *dparam)
|
||||||
const u16 config = CONFIG(MT8192_DRAM_DVFS) ? DRAMC_ENABLE_DVFS : DRAMC_DISABLE_DVFS;
|
const u16 config = CONFIG(MT8192_DRAM_DVFS) ? DRAMC_ENABLE_DVFS : DRAMC_DISABLE_DVFS;
|
||||||
if (dparam->dramc_datas.ddr_info.config_dvfs != config) {
|
if (dparam->dramc_datas.ddr_info.config_dvfs != config) {
|
||||||
printk(BIOS_WARNING,
|
printk(BIOS_WARNING,
|
||||||
"Incompatible config for calibration data from flash "
|
"DRAM-K: Incompatible config for calibration data from flash "
|
||||||
"(expected: %#x, saved: %#x)\n",
|
"(expected: %#x, saved: %#x)\n",
|
||||||
config, dparam->dramc_datas.ddr_info.config_dvfs);
|
config, dparam->dramc_datas.ddr_info.config_dvfs);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk(BIOS_INFO, "DRAM calibration data valid pass\n");
|
printk(BIOS_INFO, "DRAM-K: DRAM calibration data valid pass\n");
|
||||||
mt_set_emi(&dparam->dramc_datas);
|
mt_set_emi(&dparam->dramc_datas);
|
||||||
if (mt_mem_test(&dparam->dramc_datas) == 0)
|
if (mt_mem_test(&dparam->dramc_datas) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -72,6 +73,43 @@ static int dram_run_fast_calibration(const struct dramc_param *dparam)
|
||||||
return DRAMC_ERR_FAST_CALIBRATION;
|
return DRAMC_ERR_FAST_CALIBRATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dram_run_full_calibration(struct dramc_param *dparam)
|
||||||
|
{
|
||||||
|
/* Load and run the provided blob for full-calibration if available */
|
||||||
|
struct prog dram = PROG_INIT(PROG_REFCODE, CONFIG_CBFS_PREFIX "/dram");
|
||||||
|
|
||||||
|
initialize_dramc_param(dparam);
|
||||||
|
|
||||||
|
if (prog_locate(&dram)) {
|
||||||
|
printk(BIOS_ERR, "DRAM-K: Locate program failed\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cbfs_prog_stage_load(&dram)) {
|
||||||
|
printk(BIOS_ERR, "DRAM-K: CBFS load program failed\n");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
dparam->do_putc = do_putchar;
|
||||||
|
|
||||||
|
prog_set_entry(&dram, prog_entry(&dram), dparam);
|
||||||
|
prog_run(&dram);
|
||||||
|
if (dparam->header.status != DRAMC_SUCCESS) {
|
||||||
|
printk(BIOS_ERR, "DRAM-K: Full calibration failed: status = %d\n",
|
||||||
|
dparam->header.status);
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(dparam->header.flags & DRAMC_FLAG_HAS_SAVED_DATA)) {
|
||||||
|
printk(BIOS_ERR,
|
||||||
|
"DRAM-K: Full calibration executed without saving parameters. "
|
||||||
|
"Please ensure the blob is built properly.\n");
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void mem_init_set_default_config(struct dramc_param *dparam,
|
static void mem_init_set_default_config(struct dramc_param *dparam,
|
||||||
u32 ddr_geometry)
|
u32 ddr_geometry)
|
||||||
{
|
{
|
||||||
|
@ -93,23 +131,51 @@ static void mem_init_set_default_config(struct dramc_param *dparam,
|
||||||
static void mt_mem_init_run(struct dramc_param_ops *dparam_ops, u32 ddr_geometry)
|
static void mt_mem_init_run(struct dramc_param_ops *dparam_ops, u32 ddr_geometry)
|
||||||
{
|
{
|
||||||
struct dramc_param *dparam = dparam_ops->param;
|
struct dramc_param *dparam = dparam_ops->param;
|
||||||
|
struct stopwatch sw;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* Load calibration params from flash and run fast calibration */
|
/* Load calibration params from flash and run fast calibration */
|
||||||
mem_init_set_default_config(dparam, ddr_geometry);
|
mem_init_set_default_config(dparam, ddr_geometry);
|
||||||
if (dparam_ops->read_from_flash(dparam)) {
|
if (dparam_ops->read_from_flash(dparam)) {
|
||||||
printk(BIOS_INFO, "DRAM-K: Running fast calibration\n");
|
printk(BIOS_INFO, "DRAM-K: Running fast calibration\n");
|
||||||
if (dram_run_fast_calibration(dparam) != 0) {
|
stopwatch_init(&sw);
|
||||||
printk(BIOS_ERR, "Failed to run fast calibration\n");
|
|
||||||
|
ret = dram_run_fast_calibration(dparam);
|
||||||
|
if (ret != 0) {
|
||||||
|
printk(BIOS_ERR, "DRAM-K: Failed to run fast calibration "
|
||||||
|
"in %ld msecs, error: %d\n",
|
||||||
|
stopwatch_duration_msecs(&sw), ret);
|
||||||
|
|
||||||
/* Erase flash data after fast calibration failed */
|
/* Erase flash data after fast calibration failed */
|
||||||
memset(dparam, 0xa5, sizeof(*dparam));
|
memset(dparam, 0xa5, sizeof(*dparam));
|
||||||
dparam_ops->write_to_flash(dparam);
|
dparam_ops->write_to_flash(dparam);
|
||||||
} else {
|
} else {
|
||||||
printk(BIOS_INFO, "Fast calibration passed\n");
|
printk(BIOS_INFO, "DRAM-K: Fast calibration passed in %ld msecs\n",
|
||||||
|
stopwatch_duration_msecs(&sw));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printk(BIOS_WARNING, "Failed to read calibration data from flash\n");
|
printk(BIOS_WARNING, "DRAM-K: Failed to read calibration data from flash\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Run full calibration */
|
||||||
|
printk(BIOS_INFO, "DRAM-K: Running full calibration\n");
|
||||||
|
mem_init_set_default_config(dparam, ddr_geometry);
|
||||||
|
|
||||||
|
stopwatch_init(&sw);
|
||||||
|
int err = dram_run_full_calibration(dparam);
|
||||||
|
if (err == 0) {
|
||||||
|
printk(BIOS_INFO, "DRAM-K: Full calibration passed in %ld msecs\n",
|
||||||
|
stopwatch_duration_msecs(&sw));
|
||||||
|
|
||||||
|
dparam->header.checksum = compute_checksum(dparam);
|
||||||
|
dparam_ops->write_to_flash(dparam);
|
||||||
|
printk(BIOS_DEBUG, "DRAM-K: Calibration params saved to flash: "
|
||||||
|
"version=%#x, size=%#x\n",
|
||||||
|
dparam->header.version, dparam->header.size);
|
||||||
|
} else {
|
||||||
|
printk(BIOS_ERR, "DRAM-K: Full calibration failed in %ld msecs\n",
|
||||||
|
stopwatch_duration_msecs(&sw));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue