From 120ed1e2c5239bee1aed496516315cbf49d70bc9 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 12 Jun 2023 06:07:43 -0600 Subject: [PATCH] ec/ite: Add INTC functions to handle interrupts Add functions to enable, disable, and clear an interrupt. Signed-off-by: Tim Crawford --- src/ec/ite/ec.mk | 1 + src/ec/ite/include/ec/intc.h | 4 ++ src/ec/ite/intc.c | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/ec/ite/intc.c diff --git a/src/ec/ite/ec.mk b/src/ec/ite/ec.mk index 134a5f4..eef69a3 100644 --- a/src/ec/ite/ec.mk +++ b/src/ec/ite/ec.mk @@ -4,6 +4,7 @@ ec-y += ec.c ec-$(CONFIG_BUS_ESPI) += espi.c ec-y += gpio.c ec-y += i2c.c +ec-y += intc.c ec-y += kbc.c ec-y += pmc.c ec-y += ps2.c diff --git a/src/ec/ite/include/ec/intc.h b/src/ec/ite/include/ec/intc.h index e28509c..34fb1d2 100644 --- a/src/ec/ite/include/ec/intc.h +++ b/src/ec/ite/include/ec/intc.h @@ -134,4 +134,8 @@ static inline uint8_t intc_get_irq(void) { return IVCT - 0x10; } +void intc_enable(uint8_t nr); +void intc_disable(uint8_t nr); +void intc_clear(uint8_t nr); + #endif // _EC_INTC_H diff --git a/src/ec/ite/intc.c b/src/ec/ite/intc.c new file mode 100644 index 0000000..bbe000f --- /dev/null +++ b/src/ec/ite/intc.c @@ -0,0 +1,72 @@ +// SPDX-License-Identifier: GPL-3.0-only + +#include +#include + +struct IrqGroup { + volatile uint8_t *status; + volatile uint8_t *enable; + volatile uint8_t *level; + volatile uint8_t *polarity; +}; + +// clang-format off +#define IRQ_GROUP(nr) { \ + .status = &ISR ## nr, \ + .enable = &IER ## nr, \ + .level = &IELMR ## nr, \ + .polarity = &IPOLR ## nr, \ +} + +static const struct IrqGroup irqs[] = { + IRQ_GROUP(0), + IRQ_GROUP(1), + IRQ_GROUP(2), + IRQ_GROUP(3), + IRQ_GROUP(4), + IRQ_GROUP(5), + IRQ_GROUP(6), + IRQ_GROUP(7), + IRQ_GROUP(8), + IRQ_GROUP(9), + IRQ_GROUP(10), + IRQ_GROUP(11), + IRQ_GROUP(12), + IRQ_GROUP(13), + IRQ_GROUP(14), + IRQ_GROUP(15), + IRQ_GROUP(16), + IRQ_GROUP(17), + IRQ_GROUP(18), +#if CONFIG_EC_ITE_IT5570E + IRQ_GROUP(19), + IRQ_GROUP(20), + IRQ_GROUP(21), +#endif +}; +// clang-format on + +void intc_enable(uint8_t nr) { + // XXX: SDCC doesn't optimize division with power-of-2. + const uint8_t group = nr >> 3U; + const uint8_t bit = nr % 8U; + + *(irqs[group].status) = BIT(bit); + *(irqs[group].enable) |= BIT(bit); +} + +void intc_disable(uint8_t nr) { + // XXX: SDCC doesn't optimize division with power-of-2. + const uint8_t group = nr >> 3U; + const uint8_t bit = nr % 8U; + + *(irqs[group].enable) &= ~BIT(bit); +} + +void intc_clear(uint8_t nr) { + // XXX: SDCC doesn't optimize division with power-of-2. + const uint8_t group = nr >> 3U; + const uint8_t bit = nr % 8U; + + *(irqs[group].status) = BIT(bit); +}