Vince Liu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/86541?usp=email )
Change subject: soc/mediatek/mt8196: Move common functions to gpio_eint_v2.c ......................................................................
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 vince-wl.liu@mediatek.corp-partner.google.com Change-Id: Id21f627a49f730f3a0db786a148f81806aeba287 --- A src/soc/mediatek/common/gpio_eint_v2.c A src/soc/mediatek/common/include/soc/gpio_eint_v2.h M src/soc/mediatek/mt8196/Makefile.mk M src/soc/mediatek/mt8196/gpio_eint.c 4 files changed, 87 insertions(+), 68 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/41/86541/1
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 0000000..5e848fe --- /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 <console/console.h> +#include <soc/addressmap.h> +#include <soc/gpio.h> +#include <soc/gpio_eint_v2.h> + +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 0000000..6f4acc6 --- /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 <stdint.h> + +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 85b670a..1793104 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 f24860d..9263e9e 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 <console/console.h> -#include <soc/addressmap.h> -#include <soc/gpio.h> +#include <commonlib/bsd/helpers.h> +#include <soc/gpio_eint_v2.h>
-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_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);