From 4d3def7514e0c95532fc38b95447d7c8899934ca Mon Sep 17 00:00:00 2001 From: Vince Liu Date: Thu, 17 Jul 2025 17:36:06 +0800 Subject: [PATCH] soc/mediatek/mt8189: Fix timer reset in BL31 by using time_prepare_v2 After reboot, the system does not need to serve pending IRQ from systimer. Therefore, clear systimer IRQ pending bits in init_timer(). For that to work, the systimer compensation version 2.5 needs to be enabled. Otherwise, inaccurate timestamps may occur after BL31, for example in depthcharge. As the solution has already been implemented in time_prepare_v2, mt8189 can adopt this version to fix the issue. Also remove unnecessary headers in timer.c. BUG=b:430211678 BRANCH=none TEST=check the depthcharge timstamp in `cbmem` is correct. 554:finished TPM enable update 399,533 (12,059) 90:starting to load payload 399,541 (8) 15:starting LZMA decompress (ignore for x86) 410,775 (11,234) 16:finished LZMA decompress (ignore for x86) 465,472 (54,697) 99:selfboot jump 487,643 (22,171) 15:starting LZMA decompress (ignore for x86) 490,591 (2,948) 16:finished LZMA decompress (ignore for x86) 502,153 (11,562) 15:starting LZMA decompress (ignore for x86) 502,210 (57) 16:finished LZMA decompress (ignore for x86) 504,510 (2,300) 1000:depthcharge start 534,769 (30,259) 1002:RO vboot init 534,813 (44) 1020:vboot select&load kernel 534,815 (2) 1030:finished EC verification 554,600 (19,785) 1060:finished AuxFW Sync 560,740 (6,140) 1040:finished storage device initialization 612,960 (52,220) 1050:finished reading kernel from disk 639,711 (26,751) 1100:finished vboot kernel verification 710,596 (70,885) 1102:starting kernel decompression/relocation 731,729 (21,133) 1101:jumping to kernel 945,034 (213,305) Signed-off-by: Vince Liu Signed-off-by: Zhanzhan Ge Change-Id: Ic79003b5a5b747a3761fd4612cad6a96ada216b6 Reviewed-on: https://review.coreboot.org/c/coreboot/+/88468 Tested-by: build bot (Jenkins) Reviewed-by: Yu-Ping Wu --- src/soc/mediatek/mt8189/Makefile.mk | 2 +- src/soc/mediatek/mt8189/include/soc/timer.h | 3 +++ src/soc/mediatek/mt8189/timer.c | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/soc/mediatek/mt8189/Makefile.mk b/src/soc/mediatek/mt8189/Makefile.mk index 7c114e8a6d..b0adf83fa7 100644 --- a/src/soc/mediatek/mt8189/Makefile.mk +++ b/src/soc/mediatek/mt8189/Makefile.mk @@ -7,7 +7,7 @@ all-y += ../common/gpio.c ../common/gpio_op.c ../common/gpio_eint_v2.c gpio.c gp all-y += ../common/i2c.c ../common/i2c_common.c i2c.c all-y += ../common/pll.c pll.c all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c -all-y += ../common/timer_prepare_v1.c timer.c +all-y += ../common/timer_prepare_v2.c timer.c all-y += ../common/uart.c bootblock-y += ../common/bootblock.c bootblock.c diff --git a/src/soc/mediatek/mt8189/include/soc/timer.h b/src/soc/mediatek/mt8189/include/soc/timer.h index 60af8aac87..331b400002 100644 --- a/src/soc/mediatek/mt8189/include/soc/timer.h +++ b/src/soc/mediatek/mt8189/include/soc/timer.h @@ -8,6 +8,9 @@ #ifndef __SOC_MEDIATEK_MT8189_INCLUDE_SOC_TIMER_H__ #define __SOC_MEDIATEK_MT8189_INCLUDE_SOC_TIMER_H__ +#include #include +#define COMP_FEATURE_25_EN 0x6 + #endif /* __SOC_MEDIATEK_MT8189_INCLUDE_SOC_TIMER_H__ */ diff --git a/src/soc/mediatek/mt8189/timer.c b/src/soc/mediatek/mt8189/timer.c index 0d9776b0c2..ee49b4d57e 100644 --- a/src/soc/mediatek/mt8189/timer.c +++ b/src/soc/mediatek/mt8189/timer.c @@ -5,11 +5,15 @@ * Chapter number: 9.16 */ -#include -#include #include #include +void timer_set_compensation(void) +{ + SET32_BITFIELDS(&mtk_systimer->cntcr, + COMP_FEATURE, COMP_FEATURE_CLR | COMP_FEATURE_25_EN); +} + void init_timer(void) { timer_prepare();