From ef475cbf712f4795eddc76753669cb422388e928 Mon Sep 17 00:00:00 2001 From: Michael Hope Date: Sat, 1 Jun 2024 21:57:01 +0530 Subject: [PATCH] drivers: add the pfic interrupt controller This commit adds the pfic interrupt controller driver for WCH CH32V003. Signed-off-by: Michael Hope Signed-off-by: Dhiru Kholia --- drivers/interrupt_controller/CMakeLists.txt | 1 + drivers/interrupt_controller/Kconfig | 2 + drivers/interrupt_controller/Kconfig.wch_pfic | 9 ++++ drivers/interrupt_controller/intc_wch_pfic.c | 43 +++++++++++++++++++ .../interrupt-controller/wch,pfic.yaml | 18 ++++++++ 5 files changed, 73 insertions(+) create mode 100644 drivers/interrupt_controller/Kconfig.wch_pfic create mode 100644 drivers/interrupt_controller/intc_wch_pfic.c create mode 100644 dts/bindings/interrupt-controller/wch,pfic.yaml diff --git a/drivers/interrupt_controller/CMakeLists.txt b/drivers/interrupt_controller/CMakeLists.txt index edc0d23a633..0e458d033f2 100644 --- a/drivers/interrupt_controller/CMakeLists.txt +++ b/drivers/interrupt_controller/CMakeLists.txt @@ -43,6 +43,7 @@ zephyr_library_sources_ifdef(CONFIG_NXP_PINT intc_nxp_pint.c) zephyr_library_sources_ifdef(CONFIG_RENESAS_RA_ICU intc_renesas_ra_icu.c) zephyr_library_sources_ifdef(CONFIG_NXP_IRQSTEER intc_nxp_irqsteer.c) zephyr_library_sources_ifdef(CONFIG_INTC_MTK_ADSP intc_mtk_adsp.c) +zephyr_library_sources_ifdef(CONFIG_WCH_PFIC intc_wch_pfic.c) if(CONFIG_INTEL_VTD_ICTL) zephyr_library_include_directories(${ZEPHYR_BASE}/arch/x86/include) diff --git a/drivers/interrupt_controller/Kconfig b/drivers/interrupt_controller/Kconfig index 250309d2083..caabfc57690 100644 --- a/drivers/interrupt_controller/Kconfig +++ b/drivers/interrupt_controller/Kconfig @@ -108,4 +108,6 @@ source "drivers/interrupt_controller/Kconfig.nxp_irqsteer" source "drivers/interrupt_controller/Kconfig.mtk_adsp" +source "drivers/interrupt_controller/Kconfig.wch_pfic" + endmenu diff --git a/drivers/interrupt_controller/Kconfig.wch_pfic b/drivers/interrupt_controller/Kconfig.wch_pfic new file mode 100644 index 00000000000..79411b2f0a6 --- /dev/null +++ b/drivers/interrupt_controller/Kconfig.wch_pfic @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Michael Hope +# SPDX-License-Identifier: Apache-2.0 + +config WCH_PFIC + bool "WCH Programmable Fast Interrupt Controller (PFIC)" + default y + depends on DT_HAS_WCH_PFIC_ENABLED + help + Interrupt controller for WCH PFIC. diff --git a/drivers/interrupt_controller/intc_wch_pfic.c b/drivers/interrupt_controller/intc_wch_pfic.c new file mode 100644 index 00000000000..2eb71461c10 --- /dev/null +++ b/drivers/interrupt_controller/intc_wch_pfic.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 Michael Hope + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT wch_pfic + +#include + +#include +#include +#include +#include + +#define SEVONPEND (1 << 4) +#define WFITOWFE (1 << 3) + +void arch_irq_enable(unsigned int irq) +{ + PFIC->IENR[irq / 32] = 1 << (irq % 32); +} + +void arch_irq_disable(unsigned int irq) +{ + PFIC->IRER[irq / 32] |= 1 << (irq % 32); +} + +int arch_irq_is_enabled(unsigned int irq) +{ + return ((PFIC->ISR[irq >> 5] & (1 << (irq & 0x1F))) != 0); +} + +static int pfic_init(void) +{ + /* `wfi` is called with interrupts disabled. Configure the PFIC to wake up on any event, + * including any interrupt. + */ + PFIC->SCTLR = SEVONPEND | WFITOWFE; + return 0; +} + +SYS_INIT(pfic_init, PRE_KERNEL_1, CONFIG_INTC_INIT_PRIORITY); diff --git a/dts/bindings/interrupt-controller/wch,pfic.yaml b/dts/bindings/interrupt-controller/wch,pfic.yaml new file mode 100644 index 00000000000..89ed4a19afe --- /dev/null +++ b/dts/bindings/interrupt-controller/wch,pfic.yaml @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Michael Hope +# SPDX-License-Identifier: Apache-2.0 + +description: WCH CH32V00x Programmable Fast Interrupt Controller (PFIC) + +compatible: "wch,pfic" + +include: [interrupt-controller.yaml, base.yaml] + +properties: + reg: + required: true + + "#interrupt-cells": + const: 1 + +interrupt-cells: + - irq