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 <vince-wl.liu@mediatek.corp-partner.google.com>
Signed-off-by: Zhanzhan Ge <zhanzhan.ge@mediatek.corp-partner.google.com>
Change-Id: Ic79003b5a5b747a3761fd4612cad6a96ada216b6
Reviewed-on: https://review.coreboot.org/c/coreboot/+/88468
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
Vince Liu 2025-07-17 17:36:06 +08:00 committed by Yu-Ping Wu
commit 4d3def7514
3 changed files with 10 additions and 3 deletions

View file

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

View file

@ -8,6 +8,9 @@
#ifndef __SOC_MEDIATEK_MT8189_INCLUDE_SOC_TIMER_H__
#define __SOC_MEDIATEK_MT8189_INCLUDE_SOC_TIMER_H__
#include <soc/timer_reg.h>
#include <soc/timer_v2.h>
#define COMP_FEATURE_25_EN 0x6
#endif /* __SOC_MEDIATEK_MT8189_INCLUDE_SOC_TIMER_H__ */

View file

@ -5,11 +5,15 @@
* Chapter number: 9.16
*/
#include <arch/lib_helpers.h>
#include <commonlib/helpers.h>
#include <delay.h>
#include <soc/timer.h>
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();