soc/meidatek/mt8196: Extract common timer code for reuse
To promote code reuse and maintainability, move mt8196/timer_prepare.c to timer_prepare_v2.c. The original timer_prepare.c is renamed to timer_prepare_v1.c. Also use `mtk_systimer->cntcr` instead of `SYSTIMER_BASE` for consistency. BUG=b:379008996 BRANCH=none TEST=build passed. Signed-off-by: Vince Liu <vince-wl.liu@mediatek.corp-partner.google.com> Change-Id: Iab617e7a8bfedb81bcf673edd94d24870df7f751 Reviewed-on: https://review.coreboot.org/c/coreboot/+/88467 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Yidi Lin <yidilin@google.com> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
parent
d1c096a5b9
commit
d898653b0e
13 changed files with 90 additions and 78 deletions
39
src/soc/mediatek/common/include/soc/timer_reg.h
Normal file
39
src/soc/mediatek/common/include/soc/timer_reg.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
|
||||
|
||||
#ifndef SOC_MEDIATEK_COMMON_TIMER_REG_H
|
||||
#define SOC_MEDIATEK_COMMON_TIMER_REG_H
|
||||
|
||||
#include <device/mmio.h>
|
||||
#include <soc/addressmap.h>
|
||||
|
||||
#define SYST_CON_EN BIT(0)
|
||||
#define SYST_CON_IRQ_CLR BIT(4)
|
||||
#define REV_CLR_EN 0x3
|
||||
#define COMP_FEATURE_CLR 0
|
||||
#define SYSTIMER_CNT 8
|
||||
#define SYST_CON_CLR 0
|
||||
|
||||
struct systimer {
|
||||
u32 cntcr;
|
||||
u32 reserved;
|
||||
u32 cntcv_l;
|
||||
u32 cntcv_h;
|
||||
u32 reserved1[12];
|
||||
struct {
|
||||
u32 con;
|
||||
u32 val;
|
||||
} cnttval[SYSTIMER_CNT];
|
||||
};
|
||||
check_member(systimer, cntcr, 0x0);
|
||||
check_member(systimer, cntcv_l, 0x0008);
|
||||
check_member(systimer, cntcv_h, 0x000C);
|
||||
check_member(systimer, cnttval[0].con, 0x0040);
|
||||
check_member(systimer, cnttval[0].val, 0x0044);
|
||||
|
||||
static struct systimer *mtk_systimer = (void *)SYSTIMER_BASE;
|
||||
|
||||
DEFINE_BITFIELD(COMP_FEATURE, 12, 10)
|
||||
DEFINE_BITFIELD(REV_SET, 18, 17)
|
||||
DEFINE_BITFIELD(SYST_CON, 4, 0)
|
||||
|
||||
#endif
|
||||
|
|
@ -43,4 +43,6 @@ DEFINE_BITFIELD(GPT6_CON_MODE6, 6, 5)
|
|||
DEFINE_BITFIELD(GPT6_CLK_CLKDIV6, 3, 0)
|
||||
DEFINE_BITFIELD(GPT6_CLK_CLK6, 13, 10)
|
||||
|
||||
void timer_set_compensation(void);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#include <device/mmio.h>
|
||||
#include <soc/addressmap.h>
|
||||
#include <soc/timer.h>
|
||||
|
||||
void timer_prepare(void)
|
||||
{
|
||||
clrbits32((void *)SYSTIMER_BASE, COMP_FEATURE_MASK);
|
||||
setbits32((void *)SYSTIMER_BASE, COMP_25_MASK);
|
||||
}
|
||||
11
src/soc/mediatek/common/timer_prepare_v1.c
Normal file
11
src/soc/mediatek/common/timer_prepare_v1.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#include <device/mmio.h>
|
||||
#include <soc/timer.h>
|
||||
#include <soc/timer_reg.h>
|
||||
|
||||
void timer_prepare(void)
|
||||
{
|
||||
clrbits32(&mtk_systimer->cntcr, COMP_FEATURE_MASK);
|
||||
setbits32(&mtk_systimer->cntcr, COMP_25_MASK);
|
||||
}
|
||||
24
src/soc/mediatek/common/timer_prepare_v2.c
Normal file
24
src/soc/mediatek/common/timer_prepare_v2.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
|
||||
|
||||
#include <device/mmio.h>
|
||||
#include <soc/timer.h>
|
||||
|
||||
static void clear_systimer(void)
|
||||
{
|
||||
int id;
|
||||
|
||||
for (id = 0; id < SYSTIMER_CNT; id++) {
|
||||
u32 *cnttval_con = &mtk_systimer->cnttval[id].con;
|
||||
WRITE32_BITFIELDS(cnttval_con, SYST_CON, SYST_CON_EN);
|
||||
SET32_BITFIELDS(cnttval_con, SYST_CON, SYST_CON_IRQ_CLR);
|
||||
WRITE32_BITFIELDS(cnttval_con, SYST_CON, SYST_CON_CLR);
|
||||
}
|
||||
|
||||
SET32_BITFIELDS(&mtk_systimer->cntcr, REV_SET, REV_CLR_EN);
|
||||
}
|
||||
|
||||
void timer_prepare(void)
|
||||
{
|
||||
timer_set_compensation();
|
||||
clear_systimer();
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ all-y += ../common/gpio_eint_v1.c ../common/gpio.c ../common/gpio_op.c gpio.c
|
|||
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.c ../common/timer_prepare.c
|
||||
all-y += ../common/timer.c ../common/timer_prepare_v1.c
|
||||
all-y += ../common/uart.c
|
||||
|
||||
bootblock-y += bootblock.c
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ all-y += ../common/gpio_eint_v1.c ../common/gpio.c ../common/gpio_op.c gpio.c
|
|||
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 += timer.c ../common/timer_prepare.c
|
||||
all-y += timer.c ../common/timer_prepare_v1.c
|
||||
all-y += ../common/uart.c
|
||||
|
||||
bootblock-y += ../common/bootblock.c bootblock.c
|
||||
|
|
|
|||
|
|
@ -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.c timer.c
|
||||
all-y += ../common/timer_prepare_v1.c timer.c
|
||||
all-y += ../common/uart.c
|
||||
|
||||
bootblock-y += ../common/bootblock.c bootblock.c
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ all-y += ../common/flash_controller.c
|
|||
all-y += ../common/gpio_eint_v1.c ../common/gpio.c ../common/gpio_op.c gpio.c
|
||||
all-y += ../common/i2c.c ../common/i2c_common.c i2c.c
|
||||
all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c
|
||||
all-y += ../common/timer.c ../common/timer_prepare.c
|
||||
all-y += ../common/timer.c ../common/timer_prepare_v1.c
|
||||
all-y += ../common/uart.c
|
||||
|
||||
bootblock-y += bootblock.c
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ all-y += ../common/gpio_eint_v2.c gpio_eint.c
|
|||
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 += timer.c timer_prepare.c
|
||||
all-y += ../common/timer_prepare_v2.c timer.c
|
||||
all-y += ../common/uart.c
|
||||
|
||||
bootblock-y += booker.c
|
||||
|
|
|
|||
|
|
@ -8,40 +8,13 @@
|
|||
#ifndef SOC_MEDIATEK_MT8196_TIMER_H
|
||||
#define SOC_MEDIATEK_MT8196_TIMER_H
|
||||
|
||||
#include <soc/timer_reg.h>
|
||||
#include <soc/timer_v2.h>
|
||||
#include <stdint.h>
|
||||
|
||||
DEFINE_BITFIELD(COMP_FEATURE, 12, 10)
|
||||
DEFINE_BITFIELD(COMP_FEATURE_TIE, 4, 3)
|
||||
DEFINE_BITFIELD(REV_SET, 18, 17)
|
||||
DEFINE_BITFIELD(SYST_CON, 4, 0)
|
||||
|
||||
#define SYST_CON_EN BIT(0)
|
||||
#define SYST_CON_IRQ_CLR BIT(4)
|
||||
#define REV_CLR_EN 0x3
|
||||
#define COMP_FEATURE_20_EN 0x2
|
||||
#define COMP_FEATURE_TIE_EN 0x1
|
||||
#define COMP_FEATURE_CLR 0
|
||||
#define COMP_FEATURE_TIE_CLR 0
|
||||
#define SYSTIMER_CNT 8
|
||||
#define SYST_CON_CLR 0
|
||||
|
||||
struct systimer {
|
||||
u32 cntcr;
|
||||
u32 reserved;
|
||||
u32 cntcv_l;
|
||||
u32 cntcv_h;
|
||||
u32 reserved1[12];
|
||||
struct {
|
||||
u32 con;
|
||||
u32 val;
|
||||
} cnttval[SYSTIMER_CNT];
|
||||
};
|
||||
|
||||
check_member(systimer, cntcr, 0x0);
|
||||
check_member(systimer, cntcv_l, 0x0008);
|
||||
check_member(systimer, cntcv_h, 0x000C);
|
||||
check_member(systimer, cnttval[0].con, 0x0040);
|
||||
check_member(systimer, cnttval[0].val, 0x0044);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,8 +3,16 @@
|
|||
#include <arch/lib_helpers.h>
|
||||
#include <commonlib/helpers.h>
|
||||
#include <delay.h>
|
||||
#include <device/mmio.h>
|
||||
#include <soc/timer.h>
|
||||
|
||||
void timer_set_compensation(void)
|
||||
{
|
||||
SET32_BITFIELDS(&mtk_systimer->cntcr,
|
||||
COMP_FEATURE, COMP_FEATURE_CLR | COMP_FEATURE_20_EN,
|
||||
COMP_FEATURE_TIE, COMP_FEATURE_TIE_CLR | COMP_FEATURE_TIE_EN);
|
||||
}
|
||||
|
||||
void init_timer(void)
|
||||
{
|
||||
timer_prepare();
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
/*
|
||||
* This file is created based on MT8196 Functional Specification
|
||||
* Chapter number: 1.2 2.2
|
||||
*/
|
||||
|
||||
#include <device/mmio.h>
|
||||
#include <soc/addressmap.h>
|
||||
#include <soc/timer.h>
|
||||
|
||||
static void clear_systimer(struct systimer *const mtk_systimer)
|
||||
{
|
||||
unsigned int id = 0;
|
||||
|
||||
for (id = 0; id < SYSTIMER_CNT; id++) {
|
||||
u32 *cnttval_con = &mtk_systimer->cnttval[id].con;
|
||||
WRITE32_BITFIELDS(cnttval_con, SYST_CON, SYST_CON_EN);
|
||||
SET32_BITFIELDS(cnttval_con, SYST_CON, SYST_CON_IRQ_CLR);
|
||||
WRITE32_BITFIELDS(cnttval_con, SYST_CON, SYST_CON_CLR);
|
||||
}
|
||||
|
||||
SET32_BITFIELDS(&mtk_systimer->cntcr, REV_SET, REV_CLR_EN);
|
||||
}
|
||||
|
||||
void timer_prepare(void)
|
||||
{
|
||||
struct systimer *mtk_systimer = (void *)SYSTIMER_BASE;
|
||||
|
||||
SET32_BITFIELDS(&mtk_systimer->cntcr,
|
||||
COMP_FEATURE, COMP_FEATURE_CLR | COMP_FEATURE_20_EN,
|
||||
COMP_FEATURE_TIE, COMP_FEATURE_TIE_CLR | COMP_FEATURE_TIE_EN);
|
||||
clear_systimer(mtk_systimer);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue