From b229c120f736368b3d7fa8f7641a6b7e7022fb95 Mon Sep 17 00:00:00 2001 From: Yu-Ping Wu Date: Fri, 17 Jan 2025 17:52:33 +0800 Subject: [PATCH] soc/mediatek: Allow specifying multiple EINT base registers Unlike MT8186/MT8188/MT8192/MT8195, MT8196 has 5 EINT base registers, each with a different number of EINT bits. In preparation for the upcoming MT8196 EINT unmasking support, replace the `eint_event_reg` struct (which has a hardcoded register number) with an array `eint_event` to specify the EINT base register(s). BUG=none TEST=emerge-geralt coreboot BRANCH=none Change-Id: I86fd3109c9ff72f33b9fea45587d012b003a34ba Signed-off-by: Yu-Ping Wu Reviewed-on: https://review.coreboot.org/c/coreboot/+/86033 Reviewed-by: Yidi Lin Tested-by: build bot (Jenkins) --- src/soc/mediatek/common/eint_event.c | 26 ++++++++++++++++--- src/soc/mediatek/common/eint_event_info.c | 9 +++++++ .../mediatek/common/include/soc/eint_event.h | 16 ++++++------ src/soc/mediatek/mt8186/Makefile.mk | 2 +- src/soc/mediatek/mt8188/Makefile.mk | 2 +- src/soc/mediatek/mt8192/Makefile.mk | 2 +- src/soc/mediatek/mt8195/Makefile.mk | 2 +- 7 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 src/soc/mediatek/common/eint_event_info.c diff --git a/src/soc/mediatek/common/eint_event.c b/src/soc/mediatek/common/eint_event.c index b3538a1ddf..6e44b37192 100644 --- a/src/soc/mediatek/common/eint_event.c +++ b/src/soc/mediatek/common/eint_event.c @@ -1,10 +1,30 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include +#include #include +#include + +/* EINT reg_base + 0x880 is eint_event_mask_clr register with access type W1C. */ +#define EINT_EVENT_MASK_CLR_OFFSET 0x880 + +#define EINT_VALUE 0xFFFFFFFF + +static void enable_eint_event(const struct eint_event_info *event) +{ + uint32_t *reg = (uint32_t *)(event->reg_base + EINT_EVENT_MASK_CLR_OFFSET); + size_t port = DIV_ROUND_UP(event->eint_num, sizeof(*reg) * BITS_PER_BYTE); + int i; + + for (i = 0; i < port; i++) + write32p(reg[i], EINT_VALUE); +} void unmask_eint_event_mask(void) { - int i; - for (i = 0; i < ARRAY_SIZE(mtk_eint_event->eint_event_mask_clr); i++) - write32(&mtk_eint_event->eint_event_mask_clr[i], 0xffffffff); + const struct eint_event_info *event = &eint_event[0]; + while (event->reg_base && event->eint_num) { + enable_eint_event(event); + event++; + } } diff --git a/src/soc/mediatek/common/eint_event_info.c b/src/soc/mediatek/common/eint_event_info.c new file mode 100644 index 0000000000..706cca8143 --- /dev/null +++ b/src/soc/mediatek/common/eint_event_info.c @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#include +#include + +const struct eint_event_info eint_event[] = { + { EINT_BASE, 224 }, + {}, +}; diff --git a/src/soc/mediatek/common/include/soc/eint_event.h b/src/soc/mediatek/common/include/soc/eint_event.h index 6d544b4e7a..eab51ed562 100644 --- a/src/soc/mediatek/common/include/soc/eint_event.h +++ b/src/soc/mediatek/common/include/soc/eint_event.h @@ -3,18 +3,18 @@ #ifndef SOC_MEDIATEK_COMMON_EINT_EVENT_H #define SOC_MEDIATEK_COMMON_EINT_EVENT_H -#include -#include +#include +#include -/* eint event mask clear register */ -struct eint_event_reg { - uint32_t eint_event_mask_clr[7]; +struct eint_event_info { + uintptr_t reg_base; + size_t eint_num; }; -/* eint_base + 0x880 is eint_event_mask_clr register with access type W1C. */ -static struct eint_event_reg *const mtk_eint_event = (void *)(EINT_BASE + 0x880); +/* An element { 0, 0 } indicates the end of array. */ +extern const struct eint_event_info eint_event[]; -/* unmask eint event, eint can wakeup by spm */ +/* Unmask eint event, which can be waken up by SPM. */ void unmask_eint_event_mask(void); #endif diff --git a/src/soc/mediatek/mt8186/Makefile.mk b/src/soc/mediatek/mt8186/Makefile.mk index 0d44c2ea40..c4a3f21fbb 100644 --- a/src/soc/mediatek/mt8186/Makefile.mk +++ b/src/soc/mediatek/mt8186/Makefile.mk @@ -12,7 +12,7 @@ all-y += ../common/timer.c ../common/timer_prepare.c all-y += ../common/uart.c bootblock-y += bootblock.c -bootblock-y += ../common/eint_event.c +bootblock-y += ../common/eint_event.c ../common/eint_event_info.c bootblock-y += gic.c bootblock-y += ../common/lastbus_v1.c bootblock-y += ../common/mmu_operations.c diff --git a/src/soc/mediatek/mt8188/Makefile.mk b/src/soc/mediatek/mt8188/Makefile.mk index 2f1a0f5335..2c8379ec57 100644 --- a/src/soc/mediatek/mt8188/Makefile.mk +++ b/src/soc/mediatek/mt8188/Makefile.mk @@ -10,7 +10,7 @@ all-y += timer.c ../common/timer_prepare.c all-y += ../common/uart.c bootblock-y += ../common/bootblock.c bootblock.c -bootblock-y += ../common/eint_event.c +bootblock-y += ../common/eint_event.c ../common/eint_event_info.c bootblock-y += ../common/lastbus_v2.c lastbus.c bootblock-y += ../common/mmu_operations.c bootblock-y += ../common/tracker.c ../common/tracker_v2.c diff --git a/src/soc/mediatek/mt8192/Makefile.mk b/src/soc/mediatek/mt8192/Makefile.mk index 1c4baa8553..b2c3ced1ad 100644 --- a/src/soc/mediatek/mt8192/Makefile.mk +++ b/src/soc/mediatek/mt8192/Makefile.mk @@ -10,7 +10,7 @@ all-y += ../common/timer.c all-y += ../common/uart.c bootblock-y += bootblock.c -bootblock-y += ../common/eint_event.c +bootblock-y += ../common/eint_event.c ../common/eint_event_info.c bootblock-y += ../common/mmu_operations.c bootblock-y += ../common/pll.c pll.c bootblock-y += ../common/tracker.c ../common/tracker_v2.c diff --git a/src/soc/mediatek/mt8195/Makefile.mk b/src/soc/mediatek/mt8195/Makefile.mk index 7c3d3f44ae..ecc69657f9 100644 --- a/src/soc/mediatek/mt8195/Makefile.mk +++ b/src/soc/mediatek/mt8195/Makefile.mk @@ -11,7 +11,7 @@ all-y += ../common/uart.c bootblock-y += bootblock.c bootblock-y += ../common/early_init.c -bootblock-y += ../common/eint_event.c +bootblock-y += ../common/eint_event.c ../common/eint_event_info.c bootblock-y += ../common/mmu_operations.c bootblock-$(CONFIG_PCI) += ../common/pcie.c pcie.c bootblock-y += ../common/pll.c pll.c