From 61f7e5a6cfcd08890d9a730a8a594dbc4bc7afbe Mon Sep 17 00:00:00 2001 From: Vince Liu Date: Tue, 18 Feb 2025 14:44:37 +0800 Subject: [PATCH] soc/mediatek/mt8196: Move common functions to gpio_eint_v2.c Move gpio_get_eint_reg() and gpio_calc_eint_pos_bit() to common code to avoid redundant definitions for other platforms such as MT8189. BUG=b:379008996 BRANCH=none TEST=build passed. Signed-off-by: Vince Liu Change-Id: Id21f627a49f730f3a0db786a148f81806aeba287 Reviewed-on: https://review.coreboot.org/c/coreboot/+/86541 Reviewed-by: Yu-Ping Wu Reviewed-by: Yidi Lin Tested-by: build bot (Jenkins) --- src/soc/mediatek/common/gpio_eint_v2.c | 55 ++++++++++++++ .../common/include/soc/gpio_eint_v2.h | 25 +++++++ src/soc/mediatek/mt8196/Makefile.mk | 3 +- src/soc/mediatek/mt8196/gpio_eint.c | 72 ++----------------- 4 files changed, 87 insertions(+), 68 deletions(-) create mode 100644 src/soc/mediatek/common/gpio_eint_v2.c create mode 100644 src/soc/mediatek/common/include/soc/gpio_eint_v2.h diff --git a/src/soc/mediatek/common/gpio_eint_v2.c b/src/soc/mediatek/common/gpio_eint_v2.c new file mode 100644 index 0000000000..5e848fe279 --- /dev/null +++ b/src/soc/mediatek/common/gpio_eint_v2.c @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#include +#include +#include +#include + +void gpio_calc_eint_pos_bit(gpio_t gpio, u32 *pos, u32 *bit) +{ + uint32_t idx = gpio.id; + + *pos = 0; + *bit = 0; + + if (idx >= eint_data_len) + return; + + uint8_t index = eint_data[idx].index; + + *pos = index / MAX_EINT_REG_BITS; + *bit = index % MAX_EINT_REG_BITS; +} + +struct eint_regs *gpio_get_eint_reg(gpio_t gpio) +{ + uint32_t idx = gpio.id; + uintptr_t addr; + + if (idx >= eint_data_len) + return NULL; + + switch (eint_data[idx].instance) { + case EINT_E: + addr = EINT_E_BASE; + break; + case EINT_S: + addr = EINT_S_BASE; + break; + case EINT_W: + addr = EINT_W_BASE; + break; + case EINT_N: + addr = EINT_N_BASE; + break; + case EINT_C: + addr = EINT_C_BASE; + break; + default: + printk(BIOS_ERR, "%s: Failed to look up a valid EINT base for %d\n", + __func__, idx); + return NULL; + } + + return (void *)addr; +} diff --git a/src/soc/mediatek/common/include/soc/gpio_eint_v2.h b/src/soc/mediatek/common/include/soc/gpio_eint_v2.h new file mode 100644 index 0000000000..6f4acc61e9 --- /dev/null +++ b/src/soc/mediatek/common/include/soc/gpio_eint_v2.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ + +#ifndef __SOC_MEDIATEK_COMMON_INCLUDE_SOC_GPIO_EINT_V2_H__ +#define __SOC_MEDIATEK_COMMON_INCLUDE_SOC_GPIO_EINT_V2_H__ + +#include + +enum { + EINT_INVALID = 0, + EINT_E, + EINT_S, + EINT_W, + EINT_N, + EINT_C, +}; + +struct eint_info { + uint8_t instance; + uint8_t index; +}; + +extern const struct eint_info eint_data[]; +extern const size_t eint_data_len; + +#endif /* __SOC_MEDIATEK_COMMON_INCLUDE_SOC_GPIO_EINT_V2_H__ */ diff --git a/src/soc/mediatek/mt8196/Makefile.mk b/src/soc/mediatek/mt8196/Makefile.mk index 85b670afb3..1793104d42 100644 --- a/src/soc/mediatek/mt8196/Makefile.mk +++ b/src/soc/mediatek/mt8196/Makefile.mk @@ -3,7 +3,8 @@ ifeq ($(CONFIG_SOC_MEDIATEK_MT8196),y) all-y += ../common/flash_controller.c -all-y += ../common/gpio.c ../common/gpio_op.c gpio.c gpio_eint.c +all-y += ../common/gpio.c ../common/gpio_op.c gpio.c +all-y += ../common/gpio_eint_v2.c gpio_eint.c all-y += ../common/i2c.c i2c.c all-y += ../common/pll.c pll.c all-$(CONFIG_SPI_FLASH) += ../common/spi.c spi.c diff --git a/src/soc/mediatek/mt8196/gpio_eint.c b/src/soc/mediatek/mt8196/gpio_eint.c index f24860d128..9263e9e576 100644 --- a/src/soc/mediatek/mt8196/gpio_eint.c +++ b/src/soc/mediatek/mt8196/gpio_eint.c @@ -1,29 +1,14 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ /* * This file is created based on MT8196_EINT_Datasheet * Chapter number: 1 */ -#include -#include -#include +#include +#include -enum { - EINT_INVALID = 0, - EINT_E, - EINT_S, - EINT_W, - EINT_N, - EINT_C, -}; - -struct eint_info { - uint8_t instance; - uint8_t index; -}; - -static struct eint_info eint_data[] = { +const struct eint_info eint_data[] = { /* instance, index */ [0] = { EINT_W, 0 }, [1] = { EINT_W, 1 }, @@ -258,51 +243,4 @@ static struct eint_info eint_data[] = { }; _Static_assert(ARRAY_SIZE(eint_data) == 293, "Incorrect eint_data size"); -void gpio_calc_eint_pos_bit(gpio_t gpio, u32 *pos, u32 *bit) -{ - uint32_t idx = gpio.id; - - *pos = 0; - *bit = 0; - - if (idx >= ARRAY_SIZE(eint_data)) - return; - - uint8_t index = eint_data[idx].index; - - *pos = index / MAX_EINT_REG_BITS; - *bit = index % MAX_EINT_REG_BITS; -} - -struct eint_regs *gpio_get_eint_reg(gpio_t gpio) -{ - uint32_t idx = gpio.id; - uintptr_t addr; - - if (idx >= ARRAY_SIZE(eint_data)) - return NULL; - - switch (eint_data[idx].instance) { - case EINT_E: - addr = EINT_E_BASE; - break; - case EINT_S: - addr = EINT_S_BASE; - break; - case EINT_W: - addr = EINT_W_BASE; - break; - case EINT_N: - addr = EINT_N_BASE; - break; - case EINT_C: - addr = EINT_C_BASE; - break; - default: - printk(BIOS_ERR, "%s: Failed to look up a valid EINT base for %d\n", - __func__, idx); - return NULL; - } - - return (void *)addr; -} +const size_t eint_data_len = ARRAY_SIZE(eint_data);