soc/mediatek/common: Refactor EINT driver
Refactor EINT driver by - Move `pos_bit_calc_for_eint` to `common/gpio_eint_v1.c` and rename to `gpio_calc_eint_pos_bit`. - Implement `gpio_get_eint_reg` to obtain EINT base address. This change is prepared for the driver change in MT8196. BUG=b:334723688 TEST=EINT works on Geralt Change-Id: Ie53abc23971bfa39250ebd7dd48e28d6b91c5973 Signed-off-by: Yidi Lin <yidilin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/83703 Reviewed-by: Yu-Ping Wu <yupingso@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
parent
b60cfb89e9
commit
db5dbdf310
8 changed files with 40 additions and 22 deletions
|
|
@ -1,5 +1,6 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#include <assert.h>
|
||||
#include <device/mmio.h>
|
||||
#include <gpio.h>
|
||||
|
||||
|
|
@ -113,23 +114,16 @@ void gpio_output(gpio_t gpio, int value)
|
|||
gpio_set_mode(gpio, GPIO_MODE);
|
||||
}
|
||||
|
||||
enum {
|
||||
MAX_EINT_REG_BITS = 32,
|
||||
};
|
||||
|
||||
static void pos_bit_calc_for_eint(gpio_t gpio, u32 *pos, u32 *bit)
|
||||
{
|
||||
*pos = gpio.id / MAX_EINT_REG_BITS;
|
||||
*bit = gpio.id % MAX_EINT_REG_BITS;
|
||||
}
|
||||
|
||||
int gpio_eint_poll(gpio_t gpio)
|
||||
{
|
||||
u32 pos;
|
||||
u32 bit;
|
||||
u32 status;
|
||||
struct eint_regs *mtk_eint;
|
||||
|
||||
pos_bit_calc_for_eint(gpio, &pos, &bit);
|
||||
gpio_calc_eint_pos_bit(gpio, &pos, &bit);
|
||||
mtk_eint = gpio_get_eint_reg(gpio);
|
||||
assert(mtk_eint);
|
||||
|
||||
status = (read32(&mtk_eint->sta.regs[pos]) >> bit) & 0x1;
|
||||
|
||||
|
|
@ -143,8 +137,12 @@ void gpio_eint_configure(gpio_t gpio, enum gpio_irq_type type)
|
|||
{
|
||||
u32 pos;
|
||||
u32 bit, mask;
|
||||
struct eint_regs *mtk_eint;
|
||||
|
||||
gpio_calc_eint_pos_bit(gpio, &pos, &bit);
|
||||
mtk_eint = gpio_get_eint_reg(gpio);
|
||||
assert(mtk_eint);
|
||||
|
||||
pos_bit_calc_for_eint(gpio, &pos, &bit);
|
||||
mask = 1 << bit;
|
||||
|
||||
/* Make it an input first. */
|
||||
|
|
|
|||
15
src/soc/mediatek/common/gpio_eint_v1.c
Normal file
15
src/soc/mediatek/common/gpio_eint_v1.c
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
|
||||
#include <soc/addressmap.h>
|
||||
#include <gpio.h>
|
||||
|
||||
void gpio_calc_eint_pos_bit(gpio_t gpio, u32 *pos, u32 *bit)
|
||||
{
|
||||
*pos = gpio.id / MAX_EINT_REG_BITS;
|
||||
*bit = gpio.id % MAX_EINT_REG_BITS;
|
||||
}
|
||||
|
||||
struct eint_regs *gpio_get_eint_reg(gpio_t gpio)
|
||||
{
|
||||
return (struct eint_regs *)(EINT_BASE);
|
||||
}
|
||||
|
|
@ -102,8 +102,6 @@ struct eint_regs {
|
|||
|
||||
check_member(eint_regs, d1en, 0x420);
|
||||
|
||||
static struct eint_regs *const mtk_eint = (void *)(EINT_BASE);
|
||||
|
||||
/*
|
||||
* Firmware never enables interrupts on this platform. This function
|
||||
* reads current EINT status and clears the pending interrupt.
|
||||
|
|
@ -117,4 +115,11 @@ int gpio_eint_poll(gpio_t gpio);
|
|||
*/
|
||||
void gpio_eint_configure(gpio_t gpio, enum gpio_irq_type type);
|
||||
|
||||
enum {
|
||||
MAX_EINT_REG_BITS = 32,
|
||||
};
|
||||
|
||||
void gpio_calc_eint_pos_bit(gpio_t gpio, u32 *pos, u32 *bit);
|
||||
struct eint_regs *gpio_get_eint_reg(gpio_t gpio);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue