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
Reviewed-on: https://review.coreboot.org/c/coreboot/+/86541
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Reviewed-by: Yidi Lin <yidilin@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Vince Liu 2025-02-18 14:44:37 +08:00 committed by Matt DeVillier
commit 61f7e5a6cf
4 changed files with 87 additions and 68 deletions

View file

@ -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;
}

View file

@ -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__ */

View file

@ -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

View file

@ -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 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);