diff --git a/src/soc/mediatek/common/include/soc/timer_reg.h b/src/soc/mediatek/common/include/soc/timer_reg.h new file mode 100644 index 0000000000..df5d83272d --- /dev/null +++ b/src/soc/mediatek/common/include/soc/timer_reg.h @@ -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 +#include + +#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 diff --git a/src/soc/mediatek/common/include/soc/timer_v2.h b/src/soc/mediatek/common/include/soc/timer_v2.h index d4f854c605..c13fa7c325 100644 --- a/src/soc/mediatek/common/include/soc/timer_v2.h +++ b/src/soc/mediatek/common/include/soc/timer_v2.h @@ -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 diff --git a/src/soc/mediatek/common/timer_prepare.c b/src/soc/mediatek/common/timer_prepare.c deleted file mode 100644 index 3fb4be7f2d..0000000000 --- a/src/soc/mediatek/common/timer_prepare.c +++ /dev/null @@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ - -#include -#include -#include - -void timer_prepare(void) -{ - clrbits32((void *)SYSTIMER_BASE, COMP_FEATURE_MASK); - setbits32((void *)SYSTIMER_BASE, COMP_25_MASK); -} diff --git a/src/soc/mediatek/common/timer_prepare_v1.c b/src/soc/mediatek/common/timer_prepare_v1.c new file mode 100644 index 0000000000..5a49b1b4cf --- /dev/null +++ b/src/soc/mediatek/common/timer_prepare_v1.c @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include +#include +#include + +void timer_prepare(void) +{ + clrbits32(&mtk_systimer->cntcr, COMP_FEATURE_MASK); + setbits32(&mtk_systimer->cntcr, COMP_25_MASK); +} diff --git a/src/soc/mediatek/common/timer_prepare_v2.c b/src/soc/mediatek/common/timer_prepare_v2.c new file mode 100644 index 0000000000..8f62888983 --- /dev/null +++ b/src/soc/mediatek/common/timer_prepare_v2.c @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#include +#include + +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(); +} diff --git a/src/soc/mediatek/mt8186/Makefile.mk b/src/soc/mediatek/mt8186/Makefile.mk index 4ed3db42fc..e3592fc418 100644 --- a/src/soc/mediatek/mt8186/Makefile.mk +++ b/src/soc/mediatek/mt8186/Makefile.mk @@ -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 diff --git a/src/soc/mediatek/mt8188/Makefile.mk b/src/soc/mediatek/mt8188/Makefile.mk index 33b41835fb..0469738ff4 100644 --- a/src/soc/mediatek/mt8188/Makefile.mk +++ b/src/soc/mediatek/mt8188/Makefile.mk @@ -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 diff --git a/src/soc/mediatek/mt8189/Makefile.mk b/src/soc/mediatek/mt8189/Makefile.mk index cf44747310..7c114e8a6d 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.c timer.c +all-y += ../common/timer_prepare_v1.c timer.c all-y += ../common/uart.c bootblock-y += ../common/bootblock.c bootblock.c diff --git a/src/soc/mediatek/mt8195/Makefile.mk b/src/soc/mediatek/mt8195/Makefile.mk index bcbeb128db..35c6c63385 100644 --- a/src/soc/mediatek/mt8195/Makefile.mk +++ b/src/soc/mediatek/mt8195/Makefile.mk @@ -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 diff --git a/src/soc/mediatek/mt8196/Makefile.mk b/src/soc/mediatek/mt8196/Makefile.mk index 762dcb17cb..b6cefb37f1 100644 --- a/src/soc/mediatek/mt8196/Makefile.mk +++ b/src/soc/mediatek/mt8196/Makefile.mk @@ -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 diff --git a/src/soc/mediatek/mt8196/include/soc/timer.h b/src/soc/mediatek/mt8196/include/soc/timer.h index fbc18a9b69..6fffdc8725 100644 --- a/src/soc/mediatek/mt8196/include/soc/timer.h +++ b/src/soc/mediatek/mt8196/include/soc/timer.h @@ -8,40 +8,13 @@ #ifndef SOC_MEDIATEK_MT8196_TIMER_H #define SOC_MEDIATEK_MT8196_TIMER_H +#include #include -#include -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 diff --git a/src/soc/mediatek/mt8196/timer.c b/src/soc/mediatek/mt8196/timer.c index 5db5c4ac2f..a7f085997e 100644 --- a/src/soc/mediatek/mt8196/timer.c +++ b/src/soc/mediatek/mt8196/timer.c @@ -3,8 +3,16 @@ #include #include #include +#include #include +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(); diff --git a/src/soc/mediatek/mt8196/timer_prepare.c b/src/soc/mediatek/mt8196/timer_prepare.c deleted file mode 100644 index 08496e83d8..0000000000 --- a/src/soc/mediatek/mt8196/timer_prepare.c +++ /dev/null @@ -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 -#include -#include - -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); -}